Debian服务器上PHP DOM的UTF-8问题 [英] UTF-8 problems with PHP DOM on Debian server

查看:84
本文介绍了Debian服务器上PHP DOM的UTF-8问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Debian服务器上的PHP中的UTF-8字符串有问题。

I have a problem with UTF-8 strings in PHP on my Debian server.

详细信息更新

我做了一些测试,现在情况更加具体了。我更新了标题和详细信息以使其更适合这种情况。感谢您的答复,对于无法明确描述问题,我们深表歉意。以下脚本可以在我的本地Windows计算机上正常运行,但不能在我的Debian服务器上运行:

I´ve done a little more testing and the situation is now more specific. I updated the title and details to fit it better the situation. Thanks for the responses and sorry that the problem wasn´t described clearly. The following script works fine on my local Windows machine but not on my Debian server:

<?php
header("Content-Type: text/html; charset=UTF-8");
$string = '<html><head></head><body>UTF-8: ÄÖÜ<br /></body</html>';
$document = new DOMDocument();
@$document->loadHTML($string);
echo $document->saveHTML();
echo $string;

在我的本地计算机上,预期的输出是:

As expected on my local machine the output is:

UTF-8: ÄÖÜ
UTF-8: ÄÖÜ

在我的服务器上,输出为:

On my server the output is:

UTF-8: ÄÖÜ
UTF-8: ÄÖÜ

我使用UTF-8在Notepad ++中编写了脚本,但没有BOM并将其转移SSH。正如guido所注意到的那样,字符串本身已正确地UTF-8编码。 PHP DOM或libxml似乎有问题。并且原因必须是某些设置,因为它取决于计算机。

I wrote the script in Notepad++ in UTF-8 without BOM and transferred it over SSH. As noticed by guido the string itself is properly UTF-8 encoded. There seems to be a problem with PHP DOM or maybe libxml. And the reason must be some setting since it is machine dependant.

原始问题

我在Windows上使用XAMPP在本地工作,一切都很好。但是,当我在服务器上部署项目时,UTF-8字符串就一团糟。实际上,当我上传此测试脚本时

I work locally with XAMPP on Windows and everything is fine. But when I deploy my project on the server UTF-8 strings get all messed up. In fact when I upload this test script

echo utf8_encode('UTF-8 test: ÄÖÜ');

我得到ÃÃÃ。同样,当我用腻子连接到服务器时,也无法在外壳中正确写入变音符号(ÄÖÜ)。我不知道这个问题是否甚至与PHP有关。

I get "ÃÃÃ". Also when I connect with putty to the server I cannot write umlauts (ÄÖÜ) correctly in the shell. I have no idea if this issue is even PHP related.

推荐答案

问题的原因是libxml的旧版本(2.6 .32。)。在开发机器上为2.7.3。我将libxml升级到一个不稳定的软件包,导致版本2.7.8。问题已经解决了。

The cause of the problem was an old version of libxml (2.6.32.) on the server. On the development machine it was 2.7.3. I upgraded libxml to an unstable package resulting in version 2.7.8. The problems are now gone.

这篇关于Debian服务器上PHP DOM的UTF-8问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆