Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
In other words:
here = <<<HERE
I'm here, $foo !
HERE;
foo !
NOW;
$here is "I'm here, bar !", while $now is "I'm now, $foo !".
If you don't need variable interpolation but need special characters like $ inside your string, Nowdocs are easier to use. That's all.
Advantages / inconveniences of heredoc vs nowdoc in php - Stack Overflow
What is the point of using a Heredoc and Nowdoc while actually coding?
php - nowdoc inside a function - Stack Overflow
I got a question about php nowdoc - Stack Overflow
Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
In other words:
here = <<<HERE
I'm here, $foo !
HERE;
foo !
NOW;
$here is "I'm here, bar !", while $now is "I'm now, $foo !".
If you don't need variable interpolation but need special characters like $ inside your string, Nowdocs are easier to use. That's all.
heredocs
1. heredocs text behaves just like a double-quoted string, without the double quotes.
2. Quotes in a heredoc do not need to be escaped, but the escape codes \n linefeed,
\r carriage return,
\t horizontal tab, \v vertical tab, \e escape, \f form feed, \ backslash,\$ dollar sign,\" double-quote can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.
Example :
$myname='Tikku';
$heredoc_exmaple= <<<HEREDOC
\\n ,\\r ,\t ,\r ,\\v ,\\e ,\f ,\\ , \ ,
, $myname , ' , \$myname , \" ,\'
HEREDOC;
echo $heredoc_exmaple;
//OUTPUT \n ,\r , , ,\v ,\e , ,\ , \ ,
, Tikku , ' , $myname , \" ,\'
nowdocs
1. nowdocs text behaves just like a single-quoted string, without the single quotes.
2. Quotes in a nowdocs do not need to be escaped.Variables are not expanded in it.Advantage of nowdocs is embedding PHP code and escape codes without the need for escaping.
Example :
$myname='Tikku';
$nowdoc_exmaple= <<<'NOWDOC'
\\n ,\\r ,\t ,\r ,\\v ,\\e ,\f ,\\ , \ ,
, $myname , ' , \$myname , \" ,\'
NOWDOC;
echo $nowdoc_exmaple;
//OUTPUT \\n ,\\r ,\t ,\r ,\\v ,\\e ,\f ,\\ , \ ,
, $myname , ' , \$myname , \" ,\'
Syntax: A nowdoc is identified with the same <<< sequence used for heredocs, but the identifier which follows is enclosed in single quotes, e.g. <<<'NOWDOC'. All the rules for heredoc identifiers also apply to nowdoc identifiers, especially those regarding the appearance of the closing identifier.
So i'm studying the Heredoc and Nowdoc systems for PHP Zend exam however i can't understand what actually is there use. If arrays exist why not store strings inside of arrays?
What you have there is a heredoc, not a nowdoc. To make it a nowdoc, enclose test in quotes. You then don't need to add a backslash.
<?php
$test = <<< 'test'
<b>my name is $name</b>
test;
echo $test;
?>
From your comment elsewhere, it seems you're using a heredoc rather than a nowdoc because the PHP version you have doesn't support nowdocs. There's no way to do what you're after with a heredoc - which is why nowdocs were added. You need to upgrade to a newer version of PHP or think of a different way of meeting your higher-level requirement.
https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc