php 解析错误:语法错误,第 23 行出现意外的 T_SL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3425423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse error: syntax error, unexpected T_SL on line 23
提问by JD Isaacks
I am getting this error:
我收到此错误:
Parse error: syntax error, unexpected T_SL on line 23
解析错误:语法错误,第 23 行出现意外的 T_SL
Here is line 23:
这是第 23 行:
$selectorder = <<<ORDER
Here it is in context:
这是在上下文中:
$grid->setUrl('myfirstgrid.php');
$selectorder = <<<ORDER
function(rowid, selected)
{
if(rowid != null) {
alert("selected: "+rowid);
}
}
ORDER;
$grid->setGridEvent('onSelectRow', $selectorder);
What is causing this error?
是什么导致了这个错误?
I personally don't know what <<<
does and have never used it, I got it from a tutorial. I tried to google it, but you can't google characters like that :(
我个人不知道有什么<<<
作用,也从未使用过它,我是从教程中得到的。我试着用谷歌搜索它,但你不能用谷歌搜索这样的字符:(
回答by Matt B
Check for whitespace after <<<ORDER
. There should be no blank characters.
之后检查空格<<<ORDER
。不应有空白字符。
回答by NullUserException
<<<
is for heredoc: See manual
<<<
用于heredoc:参见手册
回答by Sarfraz
Make sure that there is no SPACE/INDENTATIONbefore ending ORDER;
确保在结束前没有空格/缩进ORDER;
回答by Terence Johnson
PHP Heredoc does not get on well with the % symbol, and the following also causes Parse error: syntax error, unexpected T_SL
:
PHP Heredoc 不能很好地处理 % 符号,以下也会导致Parse error: syntax error, unexpected T_SL
:
<?php
$var=<<<%%SHRUBBERY%%
Nih!
%%SHRUBBERY%%;
?>
回答by DaBomb
Also make sure that you have 3 '<<<'. Omitting one will throw this error. Also if your using NOWDOCs, make sure your hosting provider has php 5.3 installed. Plus if your php environment is below 5.3, do not use double quotes or single quotes.
还要确保您有 3 个“<<<”。省略一个会抛出这个错误。此外,如果您使用 NOWDOC,请确保您的托管服务提供商安装了 php 5.3。另外如果你的php环境低于5.3,不要使用双引号或单引号。
回答by David
It's called "Heredoc syntax", and it lets you specify large strings without using quotes. In this case, it looks like you're using it to put JavaScript code into a variable. Since you started the string with <<<ORDER
, you should be able to finish it with ORDER;
, as you have — but you need to make sure that ORDER;
occurs at the start of a line, with no whitespace before it.
它被称为“Heredoc 语法”,它允许您在不使用引号的情况下指定大字符串。在这种情况下,看起来您正在使用它来将 JavaScript 代码放入一个变量中。由于您以 开始字符串<<<ORDER
,因此您应该能够以 结束它ORDER;
,就像您所做的那样 - 但您需要确保它ORDER;
出现在一行的开头,并且在它之前没有空格。