What does <<< in PHP do and where can I find documentation?

I need to know that <<< does in PHP. I’ve searched the internet and found nothing. Please don’t tell me to go to php.net as I have searched there as well. I’ve seen this command used in a couple of programs, but can’t find what it does. Based on the code, it seems like it can move strings into variables.

Thanks for your help.

4 Responses to “What does <<< in PHP do and where can I find documentation?”

  • joe.attaboy:

    This is called "heredoc". It’s used to delimit a string you wish to use as output (for example, some HTML for a page).

    It’s explained here:

    http://us2.php.net/manual/en/language.types.string.php

  • The IT Guy:

    Another newcomer to PHP4 is a new syntax that is modeled after Perl’s "here printing." It is possible to display complete portions of HTML code by flanking them with either a print or echo instruction and an end label. Unlike Perl, the operator used is not a double less than sign (<<), but a triple less than sign (<<<) so as to distinguish it from the binary shift operator.

  • Graham R:

    Hi,

    I think that its similar to unix shell script in that it means take the next lines as standard input until you hit the specific tag

    for example

    echo <<<EOH
    ——— ——— — ———
    result value op test
    ——— ——— — ———
    EOH;

    would actually print out

    ——— ——— — ———
    result value op test
    ——— ——— — ———

    hope this helps
    Graham

  • digitalutopia1:

    It’s used with an identifying name and echo to print out multiple lines of text without having to escape or terminate the line for instance:

    echo <<< TEST

    <body>
    <p>Hi, I don’t have to do anything special with these lines</p>
    <img src="http://www.somesite.com/someimage.jpg"/>
    </body>

    TEST;

    Notice that whatever name you use (I used TEST, but you can use anything), you have to finish up the block with that name again, and with the semicolon.

Leave a Reply