SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Stryderjzw's Avatar
    Join Date
    May 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question "here document" syntax

    Hi,

    I was reading up on a few things and i met this "here document" syntax. I was wondering how it works.

    In the echo page of the PHP manual, there's :
    PHP Code:
    echo <<<END
    This uses the "here document" syntax to output
    multiple lines with 
    $variable interpolation. Note
    that the here document terminator must appear on a
    line with just a semicolon no extra whitespace!
    END; 
    what's with the <<<? also wut does the "END" do?

    Also in the sitepoint article "Build An Automated PHP Gallery System In Minutes" by Mayank Gandhi, he used this style too, but not in echo.
    PHP Code:
    [font=Courier New]$photo_category_list .= <<<__HTML_END 
    <option value="$row[0]">$row[1]</option>\
    __HTML_END

    } [/
    font
    So, how does all this work? Is there a webpage that describes how this works?

    Thanks in advance!

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I would recommend the manual, but you appear to already have read it...

    It's just another way of defining strings, <<<[TEXT] is the start (just like " or ') and then you use [TEXT]; as the end tag.

    It allows you to use " and ' without needing to escape them in text.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •