希望给个详细解释,最好附上每段代码的用法说明!希望不要再网上找的,我找了很多,都不好使,也许是我不懂网上的代码罢了,如果你觉得网上的代码可行,最好给我详细解释一下用法 ,以及怎么赋予变量等等...无限感激,好用的话,加50分! ----------------------------------------------------------------------------------------------- 说下我的代码: 如下是JS代码: <script type="text/javascript">document.write("<a href=rd.php?class=" + escape('行业分析') + ">行业分析</a>");</script> 对“行业分析”这几个字加密成功了的! 如下是PHP获取参数:要求解密,解密后从数据库提出数据 <? ... $class=$_GET["class"]; 请求解密(传过来的加密字符串)......HELP! $sql="select * from $demo where class = '$class' order by id desc"; $res=mysql_query($sql) or die("出错了:".mysql_error()); ?>
本例经过我测试没有问题. <? 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); ?>
|