0
Why php end tags are not used?
I read somewhere and also seen the wordpress source code that after the php script ends php end tags are not used. Why it is so?
7 Respuestas
+ 2
Santosh Pattnaik Consider two PHP scripts.
A
--------
<%php
echo "Hello world!";
%>
--------
B
--------
<%php
echo "Hello world!";
--------
The first script converts the area outside the tag to HTML. Newlines in HTML are replaced by spaces so it prints
"Hello world! " (13 character string instead of 12)
The second script prints "Hello world!" correctly. No closing tag so nothing can be outside the closing tag.
I replaced ? with % because Sololearn does not allow me to send answer that has "<?php" in it
+ 4
Did you mean the ?> was missing (omitted)?
Can you post a link to the code that was missing the end tags for verification?
+ 3
It is a PSR convention not to include the ending PHP tag in a file that contains only PHP statements.
However, if it contains HTML embedded you should add the ending PHP tags. But in most cases, it is a bad idea to mix PHP and HTML in the same file.
PHP files containing HTML are called templates and closing tags are necessary to terminate each opening PHP tag.
PHP files that do not contain HTML are called scripts and the closing tag should be omitted to avoid printing whitespace accidentally.
+ 1
Ore can you give me an example? Actually I cannot understand what kind of white space? In stackoverflow also I saw answers written about the whitespace problem but no body has given a visual example.
0
U should do <? Reform ur question please
0
Ipang check the wordpress source code, you will find this convention in almost every file.
0
Ore Thanx for the explanation.I did this common mistake every day. Now I got to know about this