Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    327
    Thanks
    84
    Thanked 8 Times in 8 Posts

    What on earth is the "<<<" notation?

    I've been coding PHP for a while and just now I've come across some new string notation here: http://php.net/manual/en/domdocument.loadxml.php

    For example:

    PHP Code:
    $str = <<<XML
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE root [
    <!ENTITY nbsp "*">
    ]>
    <div>This&nbsp;is a non-breaking space.</div>
    XML;
    What's with the <<<XML .... XML; notation? How is it different, functionally, to quoting the markup in a string?

    EDIT: Ha ha ha! I've just tried using that notation in some code and it just gives me a syntax error! Works fine with quotes though.
    Last edited by XmisterIS; 04-27-2012 at 09:52 AM.

  2. #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    15,054
    Thanks
    165
    Thanked 2,249 Times in 2,236 Posts
    It's the heredoc
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  3. Users who have thanked abduraooft for this post:

    XmisterIS (04-30-2012)

  4. #3
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,042
    Thanks
    106
    Thanked 591 Times in 578 Posts
    <<< is a heredoc. It's very useful as it allows you to return a whole load of stuff into a string with variables included in it. In the sample code you provided, everything upto the XML; will be stored in the variable called $str.

    There is also the newer nowdoc which works like this:

    $str<<<'XML'

    //stuff

    XML;

    The nowdoc will return anything literally as you see it. If you have any variables in there they will be returned as variables including the $ sign and NOT replaced by their values.
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.

  5. Users who have thanked tangoforce for this post:

    XmisterIS (04-30-2012)


 

Posting Permissions

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