转换 PHP 转义码
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,非 ASCII 字符“É”被输出为 2 个字节,这意味着它是使用 UTF 进行翻译的(而您显示它的页面很可能具有 ISO-8859 -X 字符集编码):为了防止这种情况,您可以将指令更改
为:(
此处的手册: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:
to:
(manual here: http://docs.php.net/manual/en/function.utf8-decode.php)