String html entity conversion original string: www. qdta. cnxxwxxInfo. asp? Xxlx & amp; #26053; & amp; #28216; & amp; #28909; & amp; #35759; & amp; id12939. qdta. cnxxwxxInfo. asp? Xxlx Travel News & amp; id1293 string html entity conversion
Original string: http://www.qdta.cn/xxw/xxInfo.asp? Xxlx = travel news & id = 12939
Want to convert to: http://www.qdta.cn/xxw/xxInfo.asp? Xxlx = travel news & id = 12939
What functions are used?
Share:
------ Solution --------------------
Function unescape ($ str ){
$ Str = rawurldecode ($ str );
Preg_match_all ("/(? : % U. {4 })
------ Solution --------------------
& # X. {4 };
------ Solution --------------------
& # \ D +;
------ Solution --------------------
. +/U ", $ str, $ r );
$ Ar = $ r [0];
Print_r ($ ar );
Foreach ($ ar as $ k => $ v ){
If (substr ($ v, 0, 2) = "% u ")
$ Ar [$ k] = iconv ("UCS-2", "GB2312", pack ("H4", substr ($ v,-4 )));
Elseif (substr ($ v, 0, 3) = "& # x ")
$ Ar [$ k] = iconv ("UCS-2", "UTF-8", pack ("H4", substr ($ v, 3,-1 )));
Elseif (substr ($ v, 0, 2) = "&#"){
Echo substr ($ v, 2,-1 )."
";
$ Ar [$ k] = iconv ("UCS-2", "UTF-8", pack ("n", substr ($ v, 2,-1 )));
}
}
Return join ("", $ ar );
}
------ Solution --------------------
There is a way to directly use JS, such