I've seen some people using this code.
echo <<< EOT
Hi <br>
EOT;
and
echo <<< HTML
Hello<br>
HTML;
What's the difference of those two? and why would not they use the normal echo? like
echo "How are you<br>"?
So, for example, we could use the string EOT (end of text) for our delimiter, meaning that we can use double quotes and single quotes freely within the body of the text—the string only ends when we type EOT .
Heredoc and Nowdoc are two methods for defining a string. A third and fourth way to delimit strings are the Heredoc and Nowdoc; Heredoc processes $variable and special character but Nowdoc does not processes a variable and special characters.
Heredoc is one of the ways to store or print a block of text in PHP. The data stored in the heredoc variable is more readable and error-free than other variables for using indentation and newline. How the heredoc content can be stored in a variable or printed has shown in this tutorial.
Originally Answered: What is EOT in PHP? I think what you are really talking about is heredoc syntax like this: using heredoc syntax. If this is what you meant then EOT is a marker for the php preprocessor that acts just like an ending quote would be for a string.
Difference between HTML and PHP. The main difference between HTML and PHP is that HTML is a markup language that is used to specify the content of a web page, while PHP is a scripting language.
PHP's Heredoc examples always seem to use EOT (and sometimes EOD) as the seperating string, while it is actually possible to use any string here. This works:
It doesn’t really have a meaning in PHP specifically. EOT in web programming normally means End Of Text. EOD in web programming normally means End Of Document. However, it is a common misconception that these are the only ways of opening an identifier.
Nothing, it's just a delimiter for the HEREDOC syntax. The only benefit of using HEREDOC is you can keep indents and structure of your string in the source code. It tends to be nicer to work with than concatenated strings - for your example Hi <br>
, there is no good reason to use HEREDOC.
why would not they use the normal echo?
Using heredoc for this very example makes no sense.
And it's indeed to use echo
to print out single text line.
So, nobody is using heredoc for this.
Also, in echoing large text blocks heredoc is useless again, as one have to just close PHP tag and write the text as is.
The only use of heredoc is when you need to store a large block of text in a variable.
$var = <<< HERE
Hello %s!
Please follow this link %s to continue registration.
HERE;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With