String HTML entity transformation

Source: Internet
Author: User
Original string: http://www.qdta.cn/xxw/xxInfo.asp?xxlx= Travel Hot News &id=12939
Want to convert to: http://www.qdta.cn/xxw/xxInfo.asp?xxlx= Travel Hot News &id=12939
what function do you use?


Reply to discussion (solution)

function Unescape ($str) {  $str = Rawurldecode ($STR);  Preg_match_all ("/(?:%u.{4}) |& #x. {4};|&#\d+;|.+/u", $str, $r);  $ar = $r [0];p Rint_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) = = "I") {echo substr ($v, 2,-1). "
"; $ar [$k] = Iconv ("UCS-2", "UTF-8", Pack ("n", substr ($v, 2,-1))); } } return join ("", $ar);}

function Unescape ($str) {  $str = Rawurldecode ($STR);  Preg_match_all ("/(?:%u.{4}) |& #x. {4};|&#\d+;|.+/u", $str, $r);  $ar = $r [0];p Rint_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) = = "I") {echo substr ($v, 2,-1). "
"; $ar [$k] = Iconv ("UCS-2", "UTF-8", Pack ("n", substr ($v, 2,-1))); } } return join ("", $ar);}


Originally to write their own functions ah. Just do not understand is, why some want to convert into utf-8 format? I am GBK, output, is garbled, I changed the utf-8 to GBK output normal Chinese

There is a way, directly with JS good, such as

There is a way, directly with JS good, such as



Thank you, but this part needs to be handled by PHP.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.