有人可以帮我找到$secret
行中的错误吗?
$secret
应该给出:
{"name":"JustAname","extra":"1","password":"ASD123","report":"http:\/\/website.com\/dev\/gamereport\/0001.php"}
这是PHP代码:
<?php
date_default_timezone_set('America/Montreal');
$name = 'JustAname';
$extra = '1';
$password = 'ASD123';
$reception = 'http:\/\/website.com\/dev\/gamereport.php';
// Code de génération de la base64
$secret = '{"name":"'.$name'","extra":"'.$extra'","password":"'.$password'","report":"'.$reception'"}';
$encodedSecret = base64_encode($secret);
$tournementLink = 'pvpnet://lol/customgame/joinorcreate/map1/pick6/team5/specALL/'.$encodedSecret;
echo $tournementLink;
?>
我得到:解析错误:语法错误,第20行[...]中的意外T_CONSTANT_ENCAPSED_STRING
答案 0 :(得分:2)
正如@hobbs建议的那样,你错误地连接了字符串。您还使用了未定义的变量$Tournament
,我认为它应该是$name
。试试这个:
$secret = '{"name":"' . $name . '","extra":"' . $extra . '","password":"' . $password . '","report":"' . $reception . '"}';
另外,在PHP中创建JSON的一种更好的方法是使用数组json_encode()
:
$secret = json_encode(array(
'name' => $name,
'extra' => $extra,
'password' => $password,
'report' => $reception));