开发者

Php Syntax Unexpected Sytax Error

开发者 https://www.devze.com 2023-02-12 01:18 出处:网络
I want to write like this in php. How can i express samely into php? 开发者_开发技巧$test = \'{\"longUrl\": \"http://www.yahoo.com\"}\';

I want to write like this in php. How can i express samely into php?

开发者_开发技巧
$test = '{"longUrl": "http://www.yahoo.com"}';

Thanks.


If you want to write actual PHP code to make a new object (assuming your example is JSON), there's no literal/shortcut syntax in PHP for that; you have to make a new stdClass object and set its variables manually:

$test = new stdClass;
$test->longUrl = "http://www.yahoo.com";

If you are comfortable writing JSON inside a string, as you are doing in your example, simply feed that into json_decode() and you have yourself a stdClass object:

$test = json_decode('{"longUrl": "http://www.yahoo.com"}');


$test = array("longUrl" => "http://www.yahoo.com");

>echo $test['longUrl']
http://www.yahoo.com
0

精彩评论

暂无评论...
验证码 换一张
取 消