求PHP高手:php 解密JS中的escape的代码
答案:3 悬赏:0 手机版
解决时间 2021-04-07 14:22
- 提问者网友:世勋超人
- 2021-04-07 06:51
求PHP高手:php 解密JS中的escape的代码
最佳答案
- 五星知识达人网友:蕴藏春秋
- 2021-04-07 07:36
本例经过我测试没有问题.
function utf8RawUrlDecode ($source) {
$decodedStr = "";
$pos = 0;
$len = strlen ($source);
while ($pos < $len) {
$charAt = substr ($source, $pos, 1);
if ($charAt == '%') {
$pos++;
$charAt = substr ($source, $pos, 1);
if ($charAt == 'u') {
// we got a unicode character
$pos++;
$unicodeHexVal = substr ($source, $pos, 4);
$unicode = hexdec ($unicodeHexVal);
$entity = "". $unicode . ';';
$decodedStr .= utf8_encode ($entity);
$pos += 4;
}
else {
// we have an escaped ascii character
$hexVal = substr ($source, $pos, 2);
$decodedStr .= chr (hexdec ($hexVal));
$pos += 2;
}
} else {
$decodedStr .= $charAt;
$pos++;
}
}
return $decodedStr;
}
$test = '%u884C%u4E1A%u5206%u6790';//js escape过的'行业分析';
echo utf8RawUrlDecode($test);
?>
function utf8RawUrlDecode ($source) {
$decodedStr = "";
$pos = 0;
$len = strlen ($source);
while ($pos < $len) {
$charAt = substr ($source, $pos, 1);
if ($charAt == '%') {
$pos++;
$charAt = substr ($source, $pos, 1);
if ($charAt == 'u') {
// we got a unicode character
$pos++;
$unicodeHexVal = substr ($source, $pos, 4);
$unicode = hexdec ($unicodeHexVal);
$entity = "". $unicode . ';';
$decodedStr .= utf8_encode ($entity);
$pos += 4;
}
else {
// we have an escaped ascii character
$hexVal = substr ($source, $pos, 2);
$decodedStr .= chr (hexdec ($hexVal));
$pos += 2;
}
} else {
$decodedStr .= $charAt;
$pos++;
}
}
return $decodedStr;
}
$test = '%u884C%u4E1A%u5206%u6790';//js escape过的'行业分析';
echo utf8RawUrlDecode($test);
?>
全部回答
- 1楼网友:罪歌
- 2021-04-07 09:50
1、不要用escape,这个过程是自动编码的,用不着再用js的escape函数。
2、php里用$class=urldecode($_GET["class"]);
这样就可以了。
2、php里用$class=urldecode($_GET["class"]);
这样就可以了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯