Home > Backend Development > PHP Tutorial > 有对JS熟习的吗,帮转换一段代码为PHP的

有对JS熟习的吗,帮转换一段代码为PHP的

WBOY
Release: 2016-06-13 13:00:42
Original
743 people have browsed it

有对JS熟悉的吗,帮转换一段代码为PHP的。

<script><br />
var URLEncode = {<br />
    map: {<br />
        '0': '0',<br />
        '1': '1',<br />
        '2': '2',<br />
        '3': '3',<br />
        '4': '4',<br />
        '5': '5',<br />
        '6': '6',<br />
        '7': '7',<br />
        '8': '8',<br />
        '9': '9',<br />
        '10': 'A',<br />
        '11': 'B',<br />
        '12': 'C',<br />
        '13': 'D',<br />
        '14': 'E',<br />
        '15': 'F'<br />
    },<br />
    toHex: function(num) {<br />
        var s = [];<br />
        while ( num >= 16 ) {<br />
            s.unshift( URLEncode.map[num % 16] );<br />
            num = Math.floor( num / 16 );<br />
        }<br />
        s.unshift( URLEncode.map[num] );<br />
        return '%' + s.join('');<br />
    },<br />
    exec: function(url) {<br />
        var exp = /^([a-z]+:\/\/)([^/]*)(.*)/;<br />
        var a, b, c, len, arr;<br />
        arr = url.match(exp);<br />
        a = arr[1];<br />
        b = arr[2];<br />
        c = arr[3];<br />
        len = b.length;<br />
        for (var i = 0; i < len; i++) {<br />
           a += URLEncode.toHex(b.charAt(i).charCodeAt());<br />
        }<br />
        return a + (c.length ? c : '/');<br />
    }<br />
}<br />
var teststr = 'http://baidu.com';<br />
alert('加密前: ' + teststr);<br />
alert('加密后: ' + URLEncode.exec(teststr));<br />
alert('解密后:' + unescape(URLEncode.exec(teststr)));<br />
</script><br />
Copy after login

------解决方案--------------------

var URLEncode = {<br>
	    map: {<br>
	        '0': '0',<br>
	        '1': '1',<br>
	        '2': '2',<br>
	        '3': '3',<br>
	        '4': '4',<br>
	        '5': '5', <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template