PHP - 语法错误,意外的 T_CONSTANT_ENCAPSED_STRING
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13565768/
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
PHP - syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
提问by RossDoughty
I am very new to PHP and have no idea why this is happening, I have looked at other online items, however I just cannot seem to see why I am getting this error.
我对 PHP 很陌生,不知道为什么会发生这种情况,我查看了其他在线项目,但是我似乎无法理解为什么会出现此错误。
<?php
include_once('assets/libs/posicloud/posicloud.php');
$cloud=new posicloud();
$out='';
foreach ($cloud->list_templates() as $key=>$template)
{
$out.='<option value=''.$key.'">'.$value["name"].';
}
return $out;
?>
Thankyou for any help!
感谢您的任何帮助!
回答by Rawkode
When you're working with strings in PHP you'll need to pay special attention to the formation, using "or '
当您在 PHP 中处理字符串时,您需要特别注意形成、使用"或'
$string = 'Hello, world!';
$string = "Hello, world!";
Both of these are valid, the following is not:
这两个都是有效的,以下不是:
$string = "Hello, world';
You must also note that 'inside of a literal started with "will not end the string, and vice versa. So when you have a string which contains ', it is generally best practice to use double quotation marks.
您还必须注意,'在以开头的文字内部"不会结束字符串,反之亦然。因此,当您有一个包含 的字符串时,'通常最好使用双引号。
$string = "It's ok here";
Escaping the string is also an option
转义字符串也是一种选择
$string = 'It\'s ok here too';
More information on this can be found within the documentation
可以在文档中找到有关这方面的更多信息
回答by aleation
Wrong quoting: (and missing option closing tag xd)
错误引用:(和缺少选项结束标记 xd)
$out.='<option value="'.$key.'">'.$value["name"].'</option>';
回答by Alessandro Cabutto
You have a sintax error in your code:
您的代码中有语法错误:
try changing this line
尝试改变这一行
$out.='<option value=''.$key.'">'.$value["name"].';
with
和
$out.='<option value="'.$key.'">'.$value["name"].'</option>';
回答by Luca Rainone
'<option value=''.$key.'">'
should be
应该
'<option value="'.$key.'">'
回答by silly
$out.='<option value="'.$key.'">'.$value["name"];
me funciono con esta
我 funciono con esta
"<a href='javascript:void(0)' onclick='cargar_datos_cliente(\"$row->DSC_EST\")' class='button micro asignar margin-none'>Editar</a>";

