note 41654 added to language.basic-syntax
| From: | mart3862 at yahoo dot com dot au | Date: | Sun, 18 Apr 2004 13:29:53 +0000 |
| Subject: | note 41654 added to language.basic-syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68289@lists.php.net to get a copy of this message | ||
Now the ultimate truth on how you should output xml processing instructions:
There have been several posts suggesting ways to include the text <?xml version="1.0"
encoding="utf-8"?> in your output when short_tags is turned on, but only the following
should be used:
<?php echo '<?xml version="1.0" ?'.'>' ?>
or
<?php echo "<?xml version=\"1.0\"\x3F>" ?>
Using one of these methods, and not making use of short tags, means your source code will also be a
valid XML document, which allows you to do many things with it such as validation, XSLT
translations, etc, as well as allowing your text editor to parse your code for syntax colouring.
Every PHP tag will simply be interpreted as an XML processing instruction (commonly referred to as
PI).
The reason why all the other suggested methods are not advisable is because they contain the
characters ?> inside the PHP tag, which the XML parser will interpret as the end of the
processing instruction.
A processing instruction is defined in XML as:
PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
In other words, it explicitly forbids the characters ?> to occur together within a processing
instruction, unless they are delimiting the end of the tag. It also requires a PITarget (an
identifier starting with a letter) immediately after the initial start delimiter, which means that
all short tag formats are also invalid XML.
Following these guidelines will result in code that is portable to servers with any configuration
and allow you perform many useful tasks on your XML or XHTML source documents. Even if you do not
intend to validate or translate your source documents, and you can ignore some incorrect syntax
colouring in your text editor, it is still best to get into good habits early.
----
Manual Page -- http://www.php.net/manual/en/language.basic-syntax.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41654
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41654&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41654&report=yes
Search -- http://master.php.net/manage/user-notes.php