FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » strange one
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
strange one [message #181927] Tue, 25 June 2013 01:02 Go to next message
Shelly[1] is currently offline  Shelly[1]
Messages: 16
Registered: March 2012
Karma: 0
Junior Member
My daughter also does php. She has to fix up some awful code. She came
across something that I have never seen before. It goes something like
this:

$a .= <<<BLAH;

What is that <<< ?

--
Shelly
Re: strange one [message #181928 is a reply to message #181927] Tue, 25 June 2013 01:10 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 6/24/2013 6:02 PM, Shelly wrote:
> My daughter also does php. She has to fix up some awful code. She came
> across something that I have never seen before. It goes something like
> this:
>
> $a .= <<<BLAH;
>
> What is that <<< ?
>

It is a heredoc string.

Myself I use it quite often when I am formatting output text with
variables for emails and such.

Here is the manual on it

http://www.php.net/manual/en/language.types.string.php#language.types.strin g.syntax.heredoc
Re: strange one [message #181929 is a reply to message #181927] Tue, 25 June 2013 01:14 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Monday 24 June 2013 21:02, in comp.lang.php, sheldonlg(at)thevillages(dot)net
wrote:

> My daughter also does php. She has to fix up some awful code. She came
> across something that I have never seen before. It goes something like
> this:
>
> $a .= <<<BLAH;
>
> What is that <<< ?


It is the start of a "heredoc"
http://www.php.net/manual/en/language.types.string.php#language.types.strin g.syntax.heredoc

Specifically, the word immediately adjacent to the right of the <<< (in your
case, the word BLAH) is taken as a sentinal, and all lines between the line
containing the start of the heredoc (the <<<BLAH line) and the first line
that contains the sentinal word are treated like a single string.

Thus
<<<BLAH
this is a test
one two three
four five
six
BLAH;

is treated as a single string consisting of
"this is a test\none two three\nfourfive\nsix\n"

--
Lew Pitcher
"In Skills, We Trust"
Re: strange one [message #181930 is a reply to message #181929] Tue, 25 June 2013 01:18 Go to previous messageGo to next message
Shelly[1] is currently offline  Shelly[1]
Messages: 16
Registered: March 2012
Karma: 0
Junior Member
Thank you Lew and Scott.

On 24/06/2013 21:14, Lew Pitcher wrote:
> On Monday 24 June 2013 21:02, in comp.lang.php, sheldonlg(at)thevillages(dot)net
> wrote:
>
>> My daughter also does php. She has to fix up some awful code. She came
>> across something that I have never seen before. It goes something like
>> this:
>>
>> $a .= <<<BLAH;
>>
>> What is that <<< ?
>
>
> It is the start of a "heredoc"
> http://www.php.net/manual/en/language.types.string.php#language.types.strin g.syntax.heredoc
>
> Specifically, the word immediately adjacent to the right of the <<< (in your
> case, the word BLAH) is taken as a sentinal, and all lines between the line
> containing the start of the heredoc (the <<<BLAH line) and the first line
> that contains the sentinal word are treated like a single string.
>
> Thus
> <<<BLAH
> this is a test
> one two three
> four five
> six
> BLAH;
>
> is treated as a single string consisting of
> "this is a test\none two three\nfourfive\nsix\n"
>


--
Shelly
Re: strange one [message #181949 is a reply to message #181929] Thu, 27 June 2013 16:17 Go to previous message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Mon, 24 Jun 2013 21:14:25 -0400, Lew Pitcher wrote:

> On Monday 24 June 2013 21:02, in comp.lang.php, sheldonlg(at)thevillages(dot)net
> wrote:
>
>> My daughter also does php. She has to fix up some awful code. She came
>> across something that I have never seen before. It goes something like
>> this:
>>
>> $a .= <<<BLAH;
>>
>> What is that <<< ?
>
>
> It is the start of a "heredoc"
> http://www.php.net/manual/en/language.types.string.php#language.types.strin g.syntax.heredoc
>
> Specifically, the word immediately adjacent to the right of the <<< (in your
> case, the word BLAH) is taken as a sentinal, and all lines between the line
> containing the start of the heredoc (the <<<BLAH line) and the first line
> that contains the sentinal word are treated like a single string.
>
> Thus
> <<<BLAH
> this is a test
> one two three
> four five
> six
> BLAH;
>
> is treated as a single string consisting of
> "this is a test\none two three\nfourfive\nsix\n"

thanks. I had read this about heredoc and was a tad confused on the
explanation. Your explanation clears it up.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Microsoft SQL and PHP
Next Topic: FORMS, validating mail was sent
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 21:42:48 GMT 2024

Total time taken to generate the page: 0.02335 seconds