对
PHP实现javascript中的escape和unescape
函数感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
/**
* js escape PHP 实现
* @param $string the sting want to be escaped
* @param $in_encoding
* @param $out_encoding
* @param
* @author 网: www.www.jb51.cc
**/
function escape($string,$in_encoding = 'UTF-8',$out_encoding = 'UCS-2') {
$return = '';
if (function_exists('mb_get_info')) {
for($x = 0; $x < mb_strlen ( $string,$in_encoding ); $x ++) {
$str = mb_substr ( $string,$x,1,$in_encoding );
if (strlen ( $str ) > 1) { // 多字节字符
$return .= '%u' . strtoupper ( bin2hex ( mb_convert_encoding ( $str,$out_encoding,$in_encoding ) ) );
} else {
$return .= '%' . strtoupper ( bin2hex ( $str ) );
}
}
}
return $return;
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528665.html