So I have a string that is in another language, most of it looks great, but parts of it is encoded incorrectly. How do I convert the literal string \u0026#39;n
into its unicode(?) equivalent in PHP?
The following PHP function will translate \u0026#39;n
into 'n
. This is used to communicate with the Google Translate API.
function unescapeUTF8EscapeSeq($str) {
return preg_replace_callback("/\\\u([0-9a-f]{4})/i",
create_function('$matches',
'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_QUOTES, \'UTF-8\');'
), $str);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With