php tutorial - PHP String Nowdoc - php programming - learn php - php code - php script



  • The nowdoc string creation method is similar to the heredoc method but the fact is that it works the way in single quotes as well. No parsing takes place inside the nowdoc.
  • Nowdoc statement starts with “<<<” sequence with their identifier but the identifier enclosed with single quotes (‘’).

Example for nowdoc php tutorials Syntax :

$variable= <<<’identifier’     // user defined name
content……
identifier;
click below button to copy the code. php tutorial - team

php 7 Sample Code : sample php program

<!DOCTYPE html>
<html>
    <body>
        <?php
            $var=10;
            $var1= <<<'Sample'
                This is a nowdoc string and here we call the variable $var.
                But it we not take the value of the variable,
                And also Newlines and everything else is preserved.
            Sample;
            echo $var1;
        ?>
    </body>
</html>
click below button to copy the code. php tutorial - team

php program Code Explanation :

Code Explanation for String Nowdoc In PHP

  1. In this Example “$var1” is a variable which starts with “$” dollar sign . Here the variable holds the integer value as “10”.
  2. In this Example the nowdoc string will be defined in the echo statement and it starts with “<<<” symbol with user defined name here “Sample” is define as the user defined name for nowdoc statement and since we call the value of $var which will not display the value.
  3. Inside the echo statement we specified multiple text strings which will be displayed in the browser as shown in the output.
  4. nowdoc statement is ended by the same user defined name with semicolon (;).

php coding Sample Output :

output for String Nowdoc In PHP

  1. variable name “$var” defines the string as nowdoc so the output will be displayed whose value will not be assigned for the variable “$var” apart from this, the newline spaces will also be removed as shown above.


Related Searches to php string nowdoc