将引号与字符串分开
下面的代码一直给我这个错误
解析错误:语法错误,意外的 T_VARIABLE ...
?
$query_string = 'this is a test... "this is in quotes" mmm..chicken burgers... yummm...';
preg_match_all("/\".*\"|[^\s]*/", $query_string, $matches);
echo "Matches:";
foreach($matches[0] as $token) {
echo $token . "<br />";
}
它来自这个网页
The following code keeps giving me this error
Parse error: syntax error, unexpected T_VARIABLE in ...
?
$query_string = 'this is a test... "this is in quotes" mmm..chicken burgers... yummm...';
preg_match_all("/\".*\"|[^\s]*/", $query_string, $matches);
echo "Matches:";
foreach($matches[0] as $token) {
echo $token . "<br />";
}
it is from this web page
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否查看过您注意到的错误消息中提到的行?
您是否查看了该行之前的行,以确保每行都以分号“;”结束,并使用了正确的运算符来连接变量“.”等?
这听起来像是一个简单的 PHP 语法错误。
我刚刚在我的 XAMPP 服务器上运行了以下代码,没有出现明显的错误消息:
Have you looked at the line referred to in the Error Message you noted?
Have you looked at the lines preceding that line, to ensure that you have ended each line with the semi-colon ";", that you have used the correct operators for joining variables ".", etc.?
This sounds like a simple PHP Syntax error.
I just ran the following code on my XAMPP server with no error messages apparent:
正如 Shrapnel 上校所指出的,您在代码中
$query_string
之前隐藏了破折号(十进制 173,十六进制 00ad)。去掉它,你会好很多。更新:确切地说,你有[逗号]、[空格]、[空格]、[隐藏破折号]、[空格]、'$query_string'。
As Col. Shrapnel noted, you have hidden dash symbol (173 decimal, Hex 00ad) in your code right before
$query_string
. Remove that and you'll be much better.Update: to be exact, you have [comma], [space], [space], [hidden dash], [space], '$query_string'.