【www.gdgbn.com--中文酷站】

传递中文参数,然后修改数据库教程的。

 代码如下

<script>
var url="admin/ajaxmodify.php?"+key+"=";
 url+=encodeuricomponent(encodeuricomponent(value));
  xmlhttp.open("get",url,true);
  xmlhttp.send(null);
</script>
参数是中文encodeuricomponent这个方法必须调用两次
*/

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;
}


/*
注:js中,在使用字符转码的时候,推荐使用 encodeuricomponent() 或者 encodeuri(),而非escape()。原因在于,escape() 只是为 ascii字符 做转换工作,转换成的 %unnnn 这样的码,如果要用更多的字符如 utf-8字符库就一定要用 encodeuricomponent() 或 encodeuri() 转换才可以成 %nn%nn 这的码才可以。

js:encodeuricomponent —— decodeuricomponent;php: rawurlencode —— rawurldecode


*/

本文来源:http://www.gdgbn.com/kuzhan/27386/