Jump to content

What is this? $content =<<<HTML <stuff here> HTML;


Recommended Posts

Posted

I have seen this syntax in some scripts that I have downloaded, & it interested me, so I searched for info on it, & have come up with nothing.

 

I have searched php.net, nothing... is this a php function? a way to end php so html can be used? I don't even know what to call it, it doesn't seem to follow any rules... ie: operator, function, variable.

 

I have tested it out, & used it as I have seen it being used, such as:

 

<?php

$content =<<<HTML

stuff in middle

HTML;

echo "Before ".$content." After";

 

This outputs "Before stuff in middle After".

 

if someone could point me to more information on this & what rules apply, I would be grateful.

 

Thank you

Scott

Posted

I have seen this syntax in some scripts that I have downloaded, & it interested me, so I searched for info on it, & have come up with nothing.

 

I have searched php.net, nothing... is this a php function? a way to end php so html can be used? I don't even know what to call it, it doesn't seem to follow any rules... ie: operator, function, variable.

 

I have tested it out, & used it as I have seen it being used, such as:

 

<?php

$content =<<<HTML

stuff in middle

HTML;

echo "Before ".$content." After";

 

This outputs "Before stuff in middle After".

 

if someone could point me to more information on this & what rules apply, I would be grateful.

 

Thank you

Scott

 

ok, seems I actually have found something. It seems that this is what is called heredoc syntax, & it doesn't matter what the letters are, such as

 

$content =<<<STUFF

stuff in middle

STUFF;

 

echo $content;

 

does the same as <<<HTML... & heredocs will parse for variables inside curly brackets such as:

 

$word = "foo";

$content =<<<HTML

 

stuff {$word} middle

 

HTML;

 

echo $content;

 

outputs "stuff foo middle";

 

also learned "nowdoc"s have single quotes around the "name", do similar, but do not parse content such as:

 

$word = "foo";

$content =<<<'HTML'

 

stuff {$word} middle

 

HTML;

 

echo $content;

 

outputs "stuff {$word} middle";

 

so there is what I have learned in a nutshell... if you have more info I'll still be grateful, I like to learn.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...