click below button to copy the code. php tutorial - team
php 7 Sample Code : sample php program
<!DOCTYPE html><html><body><?php$var=10;
echo <<<Sample
This is a heredoc string and here we call the variable $var.
But it will we be take the value of the variable,
And also Newlines and everything else is preserved.
Sample;?></body></html>
click below button to copy the code. php tutorial - team
php program Code Explanation :
Here we defined the variable $var1 with its value as 10.
In this Example the heredoc string will be defined in the echo statement and it starts “<<<” with the symbol along with user defined name “Sample” .
Inside the echo statement we specified multiple text strings which will be displayed in the browser as shown in the output.
The heredoc statement is terminated with the user defined name with semicolon (;).
php coding Sample Output :
Here in this output statement, variable name “$Ten” defines the string as heredoc so the output will be displayed after the interpretation of the variable “$Ten” whose value is “10” which will be assigned, where the newline spaces will be removed as shown above.