【发布时间】:2015-08-23 02:16:19
【问题描述】:
我在<<<EOF 的字符串构造中有两个嵌套语句
在语句之后,我在继续添加到字符串时收到一个我不明白的错误。
错误是unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
function foo_bar() {
$phrase = "hello world";
$string = "";
if (0 == 0) {
$string .= <<<EOF
<b>{$phrase}</b>
EOF;
if (0 == 0) {
$string .= <<<EOF
<i> of mine</i>
EOF;
}
/* comment out to see the error
$string .= <<<EOF
<u> - the END</u>
EOF;
*/
}
return $string;
}
add_shortcode('foobar', 'foo_bar');
【问题讨论】:
-
你在哪一行得到这个错误?请在您问题的代码中用注释标记它
-
当我运行这个时,我得到了“hello world of mine - the END”。
-
我们可以在这里讨论解析错误是否是主题,但您的代码doesn't even trigger one。
-
检查
EOF后面是否有空格。 -
@anantkumarsingh:因为这个问题是关于一个syntax错误,所以函数是否被调用是无关紧要的。
标签: php string if-statement eof