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.

Answer from deceze on Stack Overflow
🌐
PHP Tutorial
phptutorial.net › home › php tutorial › php heredoc
PHP Heredoc and Nowdoc Strings - PHP Tutorial
April 5, 2025 - <?php $title = 'My site'; $header = <<<HEADER <header> <h1>$title</h1> </header> HEADER; echo $header;Copy ... A nowdoc string is similar to a heredoc string except that it doesn’t expand the variables.
🌐
PHP
php.net › manual › en › language.types.string.php
PHP: Strings - Manual
Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no string interpolation is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping.
🌐
Tutorialspoint
tutorialspoint.com › php › php_heredoc_and_nowdoc.htm
PHP - Heredoc & Nowdoc
PHP provides two alternatives for declaring single or double quoted strings in the form of heredoc and newdoc syntax. Heredoc is useful for including variables, but Nowdoc is useful to get raw text without variable change.
Top answer
1 of 4
149

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.

2 of 4
3

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.

🌐
PHP.Watch
php.watch › versions › 7.3 › relaxed-heredoc-nowdoc
Heredoc and Nowdoc syntax requirements are more relaxed - PHP 7.3 • PHP.Watch
Heredoc and Nowdoc syntax, that helped to use multi-line strings had rigid requirements that the ending identifier should be the first string appearing in a new line. ... In here, the last IDENTIFIER must be the first string in a new line for this to work. In addition, there must not be any other characters after the last IDENTIFIER (other than a semi colon, which is optional). The RFC for PHP 7.3 suggested to remove the requirement above with the goal of making the code more readable.
🌐
Andycarter
andycarter.dev › blog › what-are-php-heredoc-nowdoc
What are PHP Heredoc & Nowdoc? – Andy Carter
January 16, 2019 - To denote a nowdoc we just need to use single quotes around the opening identifier:- $foo = 'bar'; echo <<<'EOT' Hello $foo Goodbye! EOT; // Output:- // Hello $foo // Goodbye! The placement of the closing identifier is important. Prior to PHP 7.3 it had to always be placed on a new line followed by a semi-colon and with no white-space in front of it.
Find elsewhere
🌐
YouTube
youtube.com › program with gio
PHP String Data Type - Heredoc & Nowdoc Syntax - Full PHP 8 Tutorial - YouTube
In this video, we go over the basic string syntax and multiline strings using Heredoc & Nowdoc syntax. I will show you when & why you would use heredoc & now...
Published: December 9, 2020
Views: 62K
🌐
phpGrid
phpgrid.com › home › php heredoc and nowdoc explained
PHP Heredoc and Nowdoc Explained | phpGrid - PHP Datagrid
February 25, 2022 - Heredoc and nowdoc are handy alternatives to the more frequently used quoted string syntax in PHP for creating strings, especially string that spans multiple lines.
🌐
Eidson
eidson.info › post › php-flexible-heredoc-nowdoc-syntax
php 7.3 - Flexible heredoc & nowdoc Syntax - eidson.info
November 26, 2017 - The only difference between a heredoc and a nowdoc is that a heredoc performs string interpolation, turning your variables into the string they represent, while a nowdoc does not.
🌐
PHP
wiki.php.net › rfc › flexible_heredoc_nowdoc_syntaxes
PHP RFC: Flexible Heredoc and Nowdoc Syntaxes
September 16, 2017 - The indentation of the closing marker dictates the amount of whitespace to strip from each line within the heredoc/nowdoc.
🌐
Laravel News
laravel-news.com › home › flexible heredoc and nowdoc coming to php 7.3
Flexible Heredoc and Nowdoc Coming to PHP 7.3
April 19, 2018 - PHP 7.3 removes this requirement: ... Nowdoc is available in PHP as of v5.3.0 and differs from Heredoc in the same way that a double-quoted string differs from a single quoted string.
🌐
Exakat
exakat.io › home › fun with delimiters of heredoc php
Fun with delimiters of Heredoc PHP - Exakat
October 7, 2015 - Heredoc PHP syntax is a way to write large bloc of text inside PHP, without the classic single quote, double quotes delimiters. It relies on <<< and a token that will also mark the end of the string.
🌐
Nelko Dev
nelkodev.com › en › blog › heredoc-and-nowdoc-in-php-a-way-to-simplify-programming
Using Heredoc and Nowdoc in PHP: Simplify your programming
June 3, 2024 - Then, we have displayed the content of the variable using the echo command. Nowdoc is a variant of heredoc that allows us to use blocks of literal text, without any interpretation or substitution of variables or special characters.
🌐
Vskills
vskills.in › home › nowdoc in php
nowdoc in php - Tutorial
April 12, 2024 - nowdoc is a syntax in PHP used to specify a string literal that is similar to single-quoted strings but doesn’t process escape sequences and variables. It is enclosed in single quotes and preceded by the keyword ‘<<<‘ followed by an identifier, which acts as a delimiter.
🌐
iWebs Technology
iwebstechnology.com › php › heredoc-and-nowdoc
PHP Tutorial - Heredoc and Nowdoc
Learn Heredoc and Nowdoc in PHP with this detailed guide including syntax, examples, and real-world applications.
🌐
Stack Overflow
stackoverflow.com › questions › 51802872 › nowdoc-inside-a-function
php - nowdoc inside a function - Stack Overflow
<?php function myfunction() { # Include the nowdoc file include(__DIR__.'/string.php'); # Return the string back return $str; }
🌐
Best Web Teacher
bestwebteacher.com › php-heredoc-nowdoc
PHP - Heredoc & Nowdoc - Tuturials
July 13, 2024 - Heredoc and Nowdoc are syntax features in PHP that allow for the creation of multiline strings without the need for escaping characters. These syntaxes
🌐
sqlpey
sqlpey.com › php › solved-how-to-differentiate-php-string-types-single-double-heredoc-nowdoc
Solved: How to Differentiate PHP String Types: Single, Double, Heredoc, and Nowdoc
July 23, 2025 - PLAIN_TEXT_BLOCK; echo $nowdocExample; /* Output: This block will display everything as raw text. Variables like $variableName are not parsed. Neither are escape sequences like \n or \t. You can freely use 'single' and "double" quotes. */ ?> A common misconception revolves around the performance difference between single and double-quoted strings. Extensive testing and insights from PHP core developers reveal there is no meaningful performance difference at runtime.