PHP 写为 ANSI 而不是 UTF-8

发布于 2024-11-17 20:51:59 字数 258 浏览 6 评论 0原文

我必须使用 Apache-PHP-MySQL 的服务器。第一个是Linux,第二个是Windows。

PHP 脚本使用 simpleXML 使用 asXML(file_name) 将字符串保存为 XML 文件。在 Linux 上 - 以 UTF-8 编码保存所有文件。 但取决于 Windows - 字符串中是否有带重音的字符,例如 òèà... - 保存为 ANSI,如果没有 - 保存为 UTF-8。 php.ini 中是否存在可以确保文件编码始终为 UTF-8 的参数? 谢谢。

I have to servers with Apache-PHP-MySQL. First is Linux, second is Windows.

The PHP script use simpleXML to save string as files XML using asXML(file_name). On Linux - saves all files in encoding UTF-8.
But on Windows depends - if there are characters with accents in string like òèà... - saves as ANSI, if no - saves as UTF-8.
Exists a parameter in php.ini or something else that can ensure that encoding of file is always UTF-8?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小嗲 2024-11-24 20:51:59

mysqli_set_charset($this->connect,'utf8');
确保您从 db 接收到的数据采用 utf-8 编码。

mysqli_set_charset($this->connect,'utf8');
ensure that from db you receive in utf-8 encoding.

你曾走过我的故事 2024-11-24 20:51:59

我的猜测是您实际上是在 ANSI 中添加字符。我怀疑 simplexml 会自动转换你的字符..所以请确保你已经事先使用了有效的 UTF-8 字符串。

My guess is that you're actually adding the characters in ANSI. I doubt simplexml does automatic conversion of your characters.. so make sure you're already using valid UTF-8 strings beforehand.

Hello爱情风 2024-11-24 20:51:59

根据此评论: http://www.php.net/manual/ en/ref.simplexml.php#79258;无论如何,SimpleXML 都会将所有内容转换为 UTF-8。

如果您想更改它,您可能需要查看 xml_parser_create(),但它仅支持 ISO-8859-1、US-ASCII 和 UTF-8 作为源编码。

http://php.net/manual/en/xml.encoding.php

According to this comment: http://www.php.net/manual/en/ref.simplexml.php#79258; SimpleXML will convert everything to UTF-8 no matter what.

If you want to change it, you may want to look into xml_parser_create() instead, but it only supports ISO-8859-1, US-ASCII and UTF-8 as source encodings.

http://php.net/manual/en/xml.encoding.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文