转换 PHP 转义码

发布于 2024-11-04 18:57:59 字数 406 浏览 0 评论 0原文

我正在使用 simplexml 读取 utf-8 XML 源的内容。

源代码包含像法语 E 这样的转义字符...

15 THE AVENUE EXAMPLE CLÉMENCEAU

我将其保存到这样的变量中:

$shipping_street1 = (string) $order->{'shipping-address'}->address1;

工作正常,但法语 E 被破坏为:

15 THE AVENUE EXAMPLE CLÉMENCEAU

我需要将值写入纯旧文本文件。我想用纯 E 替换文本,但认为必须有更好的解决方案。任何帮助表示赞赏:)

I'm using simplexml to read the contents of an utf-8 XML source.

The source contains escaped characters like the French E...

15 THE AVENUE EXAMPLE CLÉMENCEAU

And I'm saving it to a variable like this:

$shipping_street1 = (string) $order->{'shipping-address'}->address1;

That works fine but the French E gets mangled to:

15 THE AVENUE EXAMPLE CLÉMENCEAU

And I need to write the values to a plain old text file. I though about just replacing the text with a plain E but thought there must be a better solution. Any help appreciated :)

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

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

发布评论

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

评论(1

南城追梦 2024-11-11 18:57:59

事实上,非 ASCII 字符“É”被输出为 2 个字节,这意味着它是使用 UTF 进行翻译的(而您显示它的页面很可能具有 ISO-8859 -X 字符集编码):为了防止这种情况,您可以将指令更改

$shipping_street1 = (string) $order->{'shipping-address'}->address1;

为:(

$shipping_street1 = 
    utf8_decode( (string) $order->{'shipping-address'}->address1);

此处的手册:http://docs.php.net/manual/en/function.utf8-decode.php)

The fact that the non-ASCII character "É" is being output to 2 bytes means that it's been translated using UTF (while the page in which you are displaying it, very likely, has an ISO-8859-X character set encoding): to prevent this, you may change your instruction:

$shipping_street1 = (string) $order->{'shipping-address'}->address1;

to:

$shipping_street1 = 
    utf8_decode( (string) $order->{'shipping-address'}->address1);

(manual here: http://docs.php.net/manual/en/function.utf8-decode.php)

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