前端開發工程師都知道javascript有編碼函數escape()和對應的解碼函數unescape()
javascript中的escape()函數和unescape()函數用戶字符串編碼
/**
* js escape php 實現
* @param $string the sting want to be escaped
* @param $in_encoding
* @param $out_encoding
*/
function escape($string
$return =
if (function_exists(
for($x =
$str = mb_substr ( $string
if (strlen ( $str ) >
$return
} else {
$return
}
}
}
return $return;
}
對應的解碼php unescape代碼是
function unescape($str)
{
$ret =
$len = strlen($str);
for ($i =
{
if ($str[$i] ==
{
$val = hexdec(substr($str
if ($val <
$ret
else
if ($val <
$ret
chr(
else
$ret
chr(
chr(
$i +=
} else
if ($str[$i] ==
{
$ret
$i +=
} else
$ret
}
return $ret;
}
From:http://tw.wingwit.com/Article/program/PHP/201311/20860.html