新用户注册恢复喜悦村十周年

php如何直接解码javascript中的escape函数加码后的内容?

php如何直接解码javascript中的escape函数加码后的内容?
英文字母PHP直接翻译了....中文不行...
想加密代码吧
[img]http://pubimg.kuho.com/club/newbbs/13.jpg[/img]
可以的!请参考:
[PHP]
<?php
// javascript unescape function

if (!isset($str)) $str = "";

$result = uniDecode($str,'gb2312');

function uniDecode($str,$charcode="") {
  $text = preg_replace_callback("/%u[0-9A-Za-z]{4}/","toUtf8",$str);
  if (empty($charcode)) {
    return $text;
  } else {
    return mb_convert_encoding($text, $charcode, 'utf-8');
  }
}

function toUtf8($ar) {
  $c = "";
  foreach($ar as $val) {
    $val = intval(substr($val,2),16);
    if ($val < 0x7F){ // 0000-007F
      $c .= chr($val);
    } elseif ($val < 0x800) { // 0080-0800
      $c .= chr(0xC0 | ($val / 64));
      $c .= chr(0x80 | ($val % 64));
    } else { // 0800-FFFF
      $c .= chr(0xE0 | (($val / 64) / 64));
      $c .= chr(0x80 | (($val / 64) % 64));
      $c .= chr(0x80 | ($val % 64));
    }
  }
  return $c;
}

header("content-Type: text/html; charset=gb2312");

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>HP JavaScript Escape Decode</title>
</head>

<body>

<form method="OST" action="">
  <p>Score <input type="text" name="T1" size="80" onblur="document.all.str.value = escape(this.value)"></p>
  <input type="hidden" name="str" size="80">
  <input type="submit" value="Submit" name="B1">
  <input type="reset" value="Reset" name="B2"></p>
</form>
       <p>JavaScript escape code => <?=$str?></p>
       After PHP decode => <?=$result?>
</form>

</body>

</html>
[/PHP]