Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Forked from aeurielesn/util.php
Created July 24, 2018 09:09
Show Gist options
  • Save minhphong306/4b2df91a1a82d335d353d2f755f6a63b to your computer and use it in GitHub Desktop.
Save minhphong306/4b2df91a1a82d335d353d2f755f6a63b to your computer and use it in GitHub Desktop.
Decode Unicode strings in PHP
<?php
#source: http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-char
function replace_unicode_escape_sequence($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
function unicode_decode($str) {
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
}
$str = unicode_decode('\u00e9');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment