0

I have read a XML file with the simplexml_load_file() function. I suppose this function is well written and supports XML encodings correctly. My XML file is in UTF-8 format, i.e. it contains normal ANSI characters along with national characters with multibyte encoding.

So, now I want to write the XML file back with fopen() and fwrite(), also in UTF-8 format.

Should I perform some conversions to do that correctly?

Suppose variable $a contains some UTF-8 encodings. Will it be written correctly?

4

1 回答 1

0

如果您的 xml 确实已经以 utf8 编码,那么 simplexml 生成的字符串也将是 utf8。含义 - 只需将它们按原样写入文件即可。

不过,php 与底层 libxml 的接口有点时髦。即使 xml 可能是 utf8 编码的,请确保 xml 以正确的编码声明开头,否则可能会被误解。

<?xml version="1.0" encoding="UTF-8"?>
于 2012-07-15T15:48:24.237 回答