开发者

Add BOM stamp in xml by php

开发者 https://www.devze.com 2023-04-12 12:59 出处:网络
I am completing my project on fusion chart. I need to add BOMsignature in my dynamic xml. But I am unable to figure out that how can I add BOM signature for dynamic xml using 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

0

精彩评论

暂无评论...
验证码 换一张
取 消