heredocs


Heredocs >>

You know php heredocs ?? In php print function if we need to print a data which
has a big length and size, it is very complecated to enclose whole in single
quotes or in double quotes. If there is any single quotes present inside our
data , and we are using single quotes for string representation, php compiler
will show syntax error.

In these cases we can use *heredocs. *<<< is the symbol
for heredocs. Heredocs starts with this symbol (<<<) and end with a
token. See example:

print <<< UPTOEND

I can write any thing here. “This is my name”.
This is a new syntax.I
can use ‘single quotes’ also.
php is a good programming
language.
my website is sajithmr.com

UPTOEND;

?>

Here UPTOEND is the token. The above code will give the
output:

I can write any thing here. “This is my name”.
This is a new syntax.I
can use ‘single quotes’ also.
php is a good programming
language.
my website is sajithmr.com

But the thing to remeber is never confuse with the token
(delimiter)


print <<< CATS
If you like pets, yell out:
CATS AND DOGS ARE GREAT!
CATS;
?>

This will give the output:

If you like pets, yell out:
CATS AND DOGS ARE GREAT!