Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between EOT and HTML? in PHP

Tags:

php

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>"?
like image 607
Wesley Brian Lachenal Avatar asked Mar 03 '13 05:03

Wesley Brian Lachenal


People also ask

What is EOT in HTML?

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 .

What is Heredoc and Nowdoc in PHP?

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.

What is PHP Heredoc used for?

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.

What is EOT in PHP?

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.

What is the difference between HTML and PHP?

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.

Is it possible to use EOT as the seperating string in heredoc?

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:

What is the meaning of EOD in PHP?

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.


2 Answers

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.

like image 179
AlienWebguy Avatar answered Oct 21 '22 16:10

AlienWebguy


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;
like image 22
Your Common Sense Avatar answered Oct 21 '22 15:10

Your Common Sense