Add BOM stamp in xml by php
I am completing my project on fusion chart. I need to add BOM signature in my dynamic xml. But I am unable to figure out that how can I add BOM signature for dynamic xml using php. My codes are like this
$filename="a.xml";
$file= fopen("$filename", "w");
$_xml="<something/>";
fwri开发者_Python百科te($file, $_xml);
fclose($file);
In fusion chart documentation I found I need to add for general php output
header ( 'Content-type: text/xml' );
echo pack ( "C3" , 0xef, 0xbb, 0xbf );
So can any one help me with this? Thank you,
You can use a BOM as a signature no matter how the Unicode text is transformed: UTF-16, UTF-8, or UTF-32. The exact bytes comprising the BOM will be whatever the Unicode character U+FEFF
is converted into by that transformation format. In that form, the BOM serves to indicate both that it is a Unicode file, and which of the formats it is in.
If you want to, just pass a string (which is binary in PHP) that contains the BOM. Example strings:
Bytes PHP String Encoding Form
----- ---------- -------------
00 00 FE FF "\0\0\xFE\xFF" UTF-32, big-endian
FF FE 00 00 "\xFF\xFE\0\0" UTF-32, little-endian
FE FF "\xFE\xFF" UTF-16, big-endian
FF FE "\xFF\xFE" UTF-16, little-endian
EF BB BF "\xEF\xBB\xBF" UTF-8
See http://unicode.org/faq/utf_bom.html
精彩评论