As you all know, any PHP script must be surrounded by specific tags. They 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 …
We’ll be covering the following topics in this tutorial:
The various PHP code boundary markers
There are indeed several syntaxes PHP tags. Here they are detailed in the following list:
• <? 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 choose <? Php and ?> ?
Simply becaufe 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 markers by the php.ini directive short_open_tags placed to off.
• It there’s confusion with the opening tag of an XML file.
Indeed, an XML file begins with the following syntax:
Introduction to 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/CodePHP/xml.php on line 1
The only way to solve this problem is to generate the XML code using an echo statement () for example.
Solution to avoid this conflict
echo '<? xml version = "1.0" encoding = "utf-8" standalone = "yes"?> "," \ n ";