The escape () function encodes the string so that it can be read on all computers.
Grammar
Escape (String) parameter description
string is required. The string to be escaped or encoded.
return value
A copy of the encoded string. Some of these characters are replaced with 16 binary escape sequences
function PHP Tutorial Escape ($STR)
{
$sublen =strlen ($STR);
$retrunstring = "";
for ($i =0; $i < $sublen; $i + +)
{
if (Ord ($str [$i]) >=127)
{
$tmps Tutorial Tring=bin2hex (Iconv ("gb2312", "Ucs-2", substr ($str, $i, 2)));
$tmpstring =substr ($tmpstring, 2,2). substr ($tmpstring, 0,2); window may open this
$retrunstring. = "%u". $tmpstring;
$i + +;
} else {
$retrunstring. = "%". Dechex (Ord ($str [$i]);
}
}
return $retrunstring;
}
The unescape () function decodes a string encoded by escape ().
Grammar
Unescape (String) parameter description
string is required. The string to decode or reverse.
return value
A copy of the string that was decoded.
Description
This function works by finding a sequence of characters in the form%xx and%uxxxx (x for hexadecimal digits), decoding with Unicode characters u00xx and uxxxx replacing such sequences of characters.
PHP processing
function Unescape ($STR) {
$str = Rawurldecode ($STR);
Preg_match_all ("/%u.{4}|& #x .{4};|& #d +;|.+/u", $str, $r);
$ar = $r [0];
foreach ($ar as $k = = $v) {
if (substr ($v, 0,2) = = "%u")
$ar [$k] = Iconv ("Ucs-2", "GBK", Pack ("H4", substr ($v,-4)));
ElseIf (substr ($v, 0,3) = = "& #x")
$ar [$k] = Iconv ("Ucs-2", "GBK", Pack ("H4", substr ($v, 3,-1)));
ElseIf (substr ($v, 0,2) = = "the") {
$ar [$k] = Iconv ("Ucs-2", "GBK", Pack ("n", substr ($v, 2,-1)));
}
}
return join ("", $ar);
}
http://www.bkjia.com/PHPjc/632345.html www.bkjia.com true http://www.bkjia.com/PHPjc/632345.html techarticle The escape () function encodes the string so that it can be read on all computers. The syntax Escape (string) parameter describes the string required. The word to be escaped or encoded ...