Skip to content

Instantly share code, notes, and snippets.

@girvan
Created March 22, 2012 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girvan/2155364 to your computer and use it in GitHub Desktop.
Save girvan/2155364 to your computer and use it in GitHub Desktop.
function htmlhex_decode($str){
if(preg_match_all("/&#(\d+);/",$str,$match)){
foreach($match[1] as $key=>$value){
$str=str_replace($match[0][$key],"\u".dechex($value),$str);
}
}
$str=preg_replace("/&#x(\d+);/","\\u$1",$str);
$str=str_replace(Array("\r","\n"),Array("\\r","\\n"),$str);
$str="\"".$str."\"";
return json_decode($str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment