Skip to content

Instantly share code, notes, and snippets.

@kamawanu
Created April 24, 2011 14:42
Show Gist options
  • Save kamawanu/939589 to your computer and use it in GitHub Desktop.
Save kamawanu/939589 to your computer and use it in GitHub Desktop.
unescape unicode string and convert utf-8
<?php
function unicode2utf8($aa){
###var_dump(func_get_args());
return mb_convert_encoding( pack("n", hexdec($aa[1]) ), "utf-8", "ucs2" );
}
while( ($f=fgets(STDIN))!==false ){
$a = str_replace('\\','\',$a );
$a = preg_replace_callback('/\\\u([a-f0-9]{4})/i', "unicode2utf8", $f );
print $a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment