js把参数编码后传递给了php,需要php跟js一样的编码方式,在传递回js。需要js和PHP对字符串编码的统一。
JavaScript encodeURIComponent() 函数
encodeURIComponent() 函数可把字符串作为 URI 组件进行编码。
PHP以下方法与JS encodeURIComponent() 编码一致:
function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
这样就可以实现js编码与PHP编码的一致性。
来源:http://www.021yingrui.com/news.htm