且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHP中的Heredoc中使用变量(SQL练习)

更新时间:2023-02-22 16:28:36

您的heredoc需要做一些修改(因为它实际上是Nowdoc!):

Your heredoc needs a little modification (because it's actually Nowdoc!):

    echo <<<EX
    <p>Game: {$data['game_name']}<br/>
    the owner of the game is {$data['game_owner']}
    </p>
EX;

  • Heredoc标识符(与nowdoc的标识符不同)不能被引用. 'EX'需要成为EX.
  • heredoc终止符一定不能具有任何前面的空格.从文档中:

    • Heredoc identifiers (unlike nowdoc ones) cannot be quoted. 'EX' needs to become EX.
    • The heredoc terminator must not have any preceding whitespace. From the documentation:

      非常重要的一点是,带有结束标识符的行不能包含其他任何字符,除了分号(;)之外.

      It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;).

      您正在将Nowdoc与heredoc混淆.

      You're confusing Nowdoc with heredoc.

      您正在将heredoc和nowdoc混在一起.您想使用 heredoc not Nowdoc,因为您的字符串中包含变量. Heredocs是扩展"双引号字符串,而nowdocs更类似于单引号字符串,因为变量不是在nowdoc字符串中解析,而是在heredoc中.

      You're mixing up heredoc and nowdoc here. You want to use heredoc and not Nowdoc because you've got variables inside your string. Heredocs are "extended" double quoted strings, whereas nowdocs are more akin to a single quoted string, in that variables are not parsed in nowdoc strings, but are in heredoc.

      • 有关heredoc的更多信息这里.
      • 有关Nowdoc的更多信息这里.
      • More on heredoc here.
      • More on Nowdoc here.

      请更仔细地阅读文档.