As you all know, any PHP script must be surrounded by specific tags. These reserves allow the interpreter to know where in the file is PHP code to execute. On ecomputernotes.com, all presented scripts use the <? Php and?>; and it is not by chance …
The differentPHP codeboundary markers
• <?php and ?> (formal language tags)
• <? and ?> (very short tags used by novice webmasters)
• <? = And ?> (Rarely used)
• <% And %> (tag from the ASP language – rarely used)
• <script language = “php”> and </script?> (rarely used)
Why prefer <?php and ?>?
Simply because the tags <?php and ?> Ensure full portability on all servers and all versions of PHP. These are the tags default PHP.
However, “short-tags” could prevent the execution of your scripts for the following two reasons:
• The server that hosts your php pages disables the use of these tags with the short_open_tags php.ini directive placed to off.
• There continues to be confusion with the opening tag of an XML file.
In fact, an XML file begins with the following syntax:
An XML file
<? Xml version = "1.0" encoding = "utf-8" standalone = "yes"?>
Note the presence of the short tag <? at the beginning of the code and?> at the end. When reading the file, the interpreter PHP will attempt to execute this line (thinking it’s PHP) and return a parsing error similar to the one below:
Syntax error: conflict between the interpreter and the PHP XML file
• Parse error: syntax error, unexpected T_STRING in /Applications/MAMP/htdocs/Tests-PHP/xml.php on line 1
The only way to solve this problem is to generate the XML code using a PHP echo () statement for example.
Solution to avoid conflict
echo '<? xml version = "1.0" encoding = "utf-8" standalone = "yes"?> "," \ n ";
I will not change my files still …
If you do not intend to change provider, then do not change all your scripts but cons think to adopt this good practice for future applications. You are not
immune to a different configuration of a server (that of a customer for example).
Note for example that the default software EasyPHP.2 banned short tags to force developers to adopt this good practice.