php 实现javascript中的escape和unescape函数示例

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)   ***/

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...