错误声明变量PHP
问题描述:
我想声明的变量错误声明变量PHP
,我得到错误
Parse error: syntax error, unexpected 'book' (T_STRING)
mycode的
$filters = "library&loc=local,scope:("book")&loc=local,scope:("book2")....";
$path = "http://xxxxx/place/search/institution=".$filters."";
符合$filters=.....
是错误
,我不想将"..."
更改为'...'
,因为我的结果是更改
答
您需要转义双引号:
$filters = "library&loc=local,scope:(\"book\")&loc=local,scope:(\"book2\")....";
或者,您可以使用单引号将整个字符串:其中是library&loc=local,scope:("book")&loc=local,scope:("book2")....
$filters = 'library&loc=local,scope:("book")&loc=local,scope:("book2")....';
这两种结果
答
您在引起错误的变量中使用双引号。你需要逃避这些报价,例如:
scope:(\"book\")
或者使用单引号:
scope:('book')
同为第二册。
我希望这会有所帮助!
<?php
$filters = "library&loc=local,scope:(\"book\")&loc=local,scope:(\"book2\")....";
$path = "http://xxxxx/place/search/institution=".$filters."";
答
@ ARR.s “像\” 试试下面的人之前使用\。
$filters = 'library&loc=local,scope:("book")&loc=local,scope:("book2")....';
答
这应该修复它:
答
你正在使用错误的双引号:在你的字符串的开始和结束使用单引号
$filters = "library&loc=local,scope:("book")&loc=local,scope:("book2")....";
如果你想使用一个字符串中的双引号使用双引号,你声明有SCAPE他们:
$filters = "library&loc=local,scope:(\"book\")&loc=local,scope:(\"book2\")....";
无论如何,在PHP中使用双引号和单引号之间的区别在于双引号进行评估,你的情况,你没有什么评价,这样你就可以做到这一点(和PHP becouse快一点没有评估字符串)
$filters = 'library&loc=local,scope:("book")&loc=local,scope:("book2")....';
我建议你阅读php strings documentation了解双引号和单引号的字符串以及如何字符串评估工作
之间的区别
看看突出显示。如果您不想更改单引号,则需要避免引号,使其成为......范围:(\“book \”)&...' – Qirel