Cloud Strifes Cloud Strifes - 1 year ago 80
PHP Question

PHP - How convert chracters like "\xea" to correct "ê" character? (ISO-88591 - accented)

I have many characters in a text / json like:

\xea = ê
\xaa = ª (I think)

How convert to correct character in PHP?

Thanks a lot.

Answer Source

You could try something like this:

$text = preg_replace_callback('/\\\\x([0-9a-fA-F]{2})/', function ($matches) { return chr(hexdec($matches[1])); },$text);

Edit: Sorry, I just copy/pasted an old code - the e modifier is deprecated.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download