PHP version of the ESCAPE function

xiaoxiao2021-03-06  63

The URL encoding function provided by PHP is based on bytes, and the data encoded by IE's JavaScript function ESCAPE is powerless. So here, share my PHP version of the Escape / UNESCAPE function Function Escape ($ Str) {preg_match_all ("/ [/ x80- / xff]. | [/ X01- / x7f] /", $ STR, $ R) $ Ar = $ r [0]; Foreach ($ AS $ K => $ V) {IF (ORD ($ V [0]) <128) $ AR [$ K] = RAWURLENCODE ($ V); ELSE $ AR [$ K] = "% u" .bin2hex (Iconv ("GB2312", "UCS-2", $ V));} Return Join ("", $ A);}

Function UNESCAPE ($ str) {$ str = rawurldecode ($ STR); preg_match_all ("/ (?:% u. {4}) | $ ar = $ r [0 ]; Foreach ($ AR AS $ K => $ V) {IF (Substr ($ V, 0, 2) == "% U" && Strlen ($ V) == 6) $ AR [$ K] = iconv ("UCS-2", "GB2312", PACK ("H4", Substr ($ V, -4)));} Return Join ("", $ A);}

转载请注明原文地址:https://www.9cbs.com/read-90886.html

New Post(0)