PHP-语法错误,意外T_CONSTANT_ENCAPSED_STRING [英] PHP - syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
问题描述
我对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;
?>
谢谢您的帮助!
在PHP中使用字符串时,需要特别注意使用"
或'
$string = 'Hello, world!';
$string = "Hello, world!";
这两个都是有效的,以下是无效的:
$string = "Hello, world';
您还必须注意,以"
开头的文字内的'
不会以字符串结尾,反之亦然.因此,当您的字符串包含'
时,通常最好的做法是使用双引号.
$string = "It's ok here";
转义字符串也是一种选择
$string = 'It\'s ok here too';
有关更多信息,请参见文档 >
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
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!
When you're working with strings in PHP you'll need to pay special attention to the formation, using "
or '
$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
这篇关于PHP-语法错误,意外T_CONSTANT_ENCAPSED_STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!