php tutorial - PHP String Heredoc - php programming - learn php - php code - php script
- The string heredoc methodology is used to create fairly complex strings which is mentioned in double quotes (“ “).
- The heredoc supports all the features of double quotes and allows creating the string values with more than one line without concatenations.
- Using double quotes, if we create strings that have multiple lines it will generate errors.
- In terms of php heredoc starts with “<<<” symbol with the user defined name.
- The heredoc statement ends with the user defined name terminated by the semicolon (;).
- On using the heredoc statement it will defined as the double quoted (““) string that is escape characters are interpreted.
Example for heredoc php tutorials Syntax :
php 7 Sample Code : sample php program
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.