Home > Article > Backend Development > What is the purpose of the \"
Understanding the PHP Heredoc Syntax: What does "<<<" Represent?
In PHP, the "<<<" syntax is used to create a heredoc string. Here's how it works:
Starting a Heredoc String
To initiate a heredoc string, use the following syntax:
<<<HEREDOC_TOKEN
where HEREDOC_TOKEN can be any word or phrase.
Example:
$sql = <<<MySQL_QUERY
Ending a Heredoc String
To terminate the heredoc string, simply place the HEREDOC_TOKEN on a new line, followed by nothing else:
HEREDOC_TOKEN
As an exception, you can optionally include a single semicolon after the end token.
Preserving Newlines and Content
The heredoc syntax allows you to create multiline strings with preserved newlines and other content. This can be useful for generating SQL queries, HTML templates, or other text-based outputs.
Example
The following code uses a heredoc string to generate an HTML header:
echo <<My Website Welcome to my site!