PHP-语法错误,意外T_CONSTANT_ENCAPSED_STRING [英] PHP - syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

查看:146
本文介绍了PHP-语法错误,意外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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆