开发者

Converting PHP escape codes

开发者 https://www.devze.com 2023-03-02 17:47 出处:网络
I\'m using simplexml to read the contents of an utf-8 XML source. The source contains escaped characters like the French 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 th开发者_Python百科e text with a plain E but thought there must be a better solution. Any help appreciated :)


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消