Jump to content
Killersites Community
Sign in to follow this  
sb17joker

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

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×