【问题标题】:PHP statements with <<<EOF string [duplicate]带有 <<<EOF 字符串的 PHP 语句 [重复]
【发布时间】:2015-08-23 02:16:19
【问题描述】:

我在&lt;&lt;&lt;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


【解决方案1】:

所以上面的 cmets 中讨论的要点。

检查EOF;之后的尾随空格

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    • 2010-10-14
    • 2020-12-06
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 2019-04-27
    相关资源
    最近更新 更多