PHP 语法错误 T_ENCAPSED_AND_WHITESPACE [英] PHP syntax error T_ENCAPSED_AND_WHITESPACE

查看:49
本文介绍了PHP 语法错误 T_ENCAPSED_AND_WHITESPACE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 php 基础知识,但在理解如何将代码与字符串混合使用时遇到了一些问题.

i'm starting to work with php basics and i have some problem understanding how mix code with strings.

我发现了一种非常有用的样式来打印字符串块,但我不知道名称,也找不到示例.

I found a great and useful style to print string blocks but i don't know the name and i'm not able to find examples.

下面的代码返回错误:
解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,在第 120 行的/web/htdocs/food/user/index.php 中需要 T_STRING 或 T_VARIABLE 或 T_NUM_STRING

the code below return me the error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /web/htdocs/food/user/index.php on line 120

<?php   
$html_str = <<<STR
    <li><img alt="hello" src="$path_images/pencil.png"/><a title="hello" href="$path_pages/$page/action">Details</a></li>

STR;
print $html_str;
?>

有人可以帮我找出我错在哪里以及这种语法风格的名称吗?

can someone help me to find where i'm wrong and the name of this syntax style?

谢谢

推荐答案

我发现问题了!
在我发布的示例中,它无法返回错误:

I've found the problem!
in the example I've posted it can't return the error:

工作代码

<?php
$str = <<<STRING
hello! this is a working string<br/>
and i can do too many things with heredoc syntax!
STRING;

print $str;
?>

不工作的代码

<?php
     $str = <<<STRING
     syntax error!<br/>
     syntax error!<br/>
     why?
     STRING;

     print $str;
?>

问题在于关闭标签 STRING; 之前的选项卡被认为是标签的一部分,因此关闭标签不会被解释为 "STRING;" 而是        STRING;",这就是它不起作用的原因.

The problem are the tabs before the close tag STRING; which are considered part of tag, so the close tag is not interpreted "STRING;" but "        STRING;", that's why it doesn't work.

希望它对其他人有用.

这篇关于PHP 语法错误 T_ENCAPSED_AND_WHITESPACE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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