对php实现javascript中的escape和unescape函数感兴趣的小伙伴,下面一起跟随512笔记的小编两巴掌来看看吧!
/**
* js escape php 实现
* @param $string the sting want to be escaped
* @param $in_encoding
* @param $out_encoding
* @param
* @author 五一二笔记网: www.512PiC.com
**/
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;
}
/*** 来自512笔记(www.512pic.com) ***/
注:关于php 实现javascript中的escape和unescape函数示例的内容就先介绍到这里,更多相关文章的可以留意512笔记的其他信息。
关键词:escape,unescape
您可能感兴趣的文章