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

内容摘要
这篇文章主要为大家详细介绍了php 实现javascript中的escape和unescape函数示例,具有一定的参考价值,可以用来参考一下。

对php实现javascript中的escape和unescape函数对此
文章正文

这篇文章主要为大家详细介绍了php 实现javascript中的escape和unescape函数示例,具有一定的参考价值,可以用来参考一下。

对php实现javascript中的escape和unescape函数对此感兴趣的朋友,看看idc笔记做的技术笔记!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<code class="php">
/**
 * 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;
}
/***   来自php教程(www.idcnote.com)   ***/</code>

注:关于php 实现javascript中的escape和unescape函数示例的内容就先介绍到这里,更多相关文章的可以留意

代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!