How do I use that "<<<HTML" thing in PHP?

This question already has an answer here:

  • PHP expression <<<EOB 5 answers

  • In PHP, this syntax is called a heredoc. The linked documentation contains some helpful examples.


    To end it, type:

    echo <<<SOMESTUFF
    ...
    SOMESTUFF
    

    With SOMESTUFF being on a line of its own. See the PHP manual on "heredocs" for more info.


    This is called Heredoc syntax, and allows you to define long strings, without having to care about escaping double-quotes (nor single, btw)

    Syntax goes like this :

    $str = <<<EOD
    Example of string
    spanning multiple lines
    using heredoc syntax.
    EOD;
    

    Note this (quoting the doc) :

    A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

    The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

    And also note it is not exactly the same as nowdoc syntax, which only exists since PHP >= 5.3

    链接地址: http://www.djcxy.com/p/58448.html

    上一篇: 关于PHP函数的文档<<< OUT

    下一篇: 我如何在PHP中使用“<<< HTML”的东西?