Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php在xml中添加BOM戳记_Php_Xml_Fopen_Byte Order Mark - Fatal编程技术网

用php在xml中添加BOM戳记

用php在xml中添加BOM戳记,php,xml,fopen,byte-order-mark,Php,Xml,Fopen,Byte Order Mark,我正在完成fusion图表上的项目。我需要在动态xml中添加BOM签名。但我不知道如何使用php为动态xml添加BOM签名。 我的密码是这样的 $filename="a.xml"; $file= fopen("$filename", "w"); $_xml="<something/>"; fwrite($file, $_xml); fclose($file); 有人能帮我吗? 谢谢,无论Unicode文本如何转换,您都可以使用BOM作为签名:UTF-16、UTF-8或UTF-32。

我正在完成fusion图表上的项目。我需要在动态xml中添加BOM签名。但我不知道如何使用php为动态xml添加BOM签名。 我的密码是这样的

$filename="a.xml";
$file= fopen("$filename", "w");
$_xml="<something/>";
fwrite($file, $_xml);
fclose($file);
有人能帮我吗?
谢谢,

无论Unicode文本如何转换,您都可以使用BOM作为签名:UTF-16、UTF-8或UTF-32。组成BOM表的确切字节将是Unicode字符
U+FEFF
通过该转换格式转换成的任何字符。在这种形式下,BOM表用于指示它是一个Unicode文件,以及它采用哪种格式

如果需要,只需传递一个包含BOM的字符串(在PHP中是二进制的)。示例字符串:

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

请参见

您的文件使用的字符集/编码是什么?您是在utf-16模式下编写的吗?对于UTF-8输出,BOM是不必要的(并且建议不要)。@Marc B我不是用UTF写的-16@DAKSH:ANSI没有BOM表,请参阅我的答案哪些编码表单有BOM表。@Marc B:我不想推荐它,但您可以使用BOM表指定文件为UTF-8格式。
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