<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="skins/JinnStyleV1/article.xslt"?><blog view="688301" processed="0.07" queries="8" focusMarkup="" xslt="skins/JinnStyleV1/article.xslt"><panels><panel id="1" sn="0" sys="true"><name>Blog Main</name><content><article id="131" disComm="false"><title>用 Script  实现 UrlEncode 和 UrlDecode</title><category id="26"><name>网络开发</name><icon>images/icons/14.gif</icon></category><content><![CDATA[<textarea name='code' class='xml' cols='50'>&lt;script language=&quot;vbscript&quot;&gt;
Function str2asc(strstr)
    str2asc = Hex(asc(strstr))
End Function
Function asc2str(ascasc)
    asc2str = Chr(ascasc)
End Function
&lt;/script&gt;
&lt;script language=&quot;javascript&quot;&gt;
function UrlEncode(str){
    var ret = &quot;&quot;;
    var strSpecial = &quot;!\&quot;#$%&amp;'()*+,/:;&lt;=&gt;?[]^`{|}~%&quot;;
    for (var i=0; i&lt;str.length; i++) {
        var chr = str.charAt(i);
        var c = str2asc(chr);
        if (parseInt(&quot;0x&quot;+c) &gt; 0x7f) {
            ret += &quot;%&quot; + c.slice(0,2) + &quot;%&quot; + c.slice(-2);
        } else {
            if (chr == &quot; &quot;)
                ret += &quot;+&quot;;
            else if (strSpecial.indexOf(chr) != -1)
                ret += &quot;%&quot; + c.toString(16);
            else
                ret += chr;
        }
    }
    return ret;
}
function UrlDecode(str) {
    var ret = &quot;&quot;;
    for (var i=0; i&lt;str.length; i++) {
     var chr = str.charAt(i);
        if (chr == &quot;+&quot;) {
            ret+=&quot; &quot;;
        } else if(chr==&quot;%&quot;) {
            var asc = str.substring(i+1,i+3);
            if (parseInt(&quot;0x&quot;+asc)&gt;0x7f) {
                ret+=asc2str(parseInt(&quot;0x&quot;+asc+str.substring(i+4,i+6)));
                i+=5;
             } else {
                ret+=asc2str(parseInt(&quot;0x&quot;+asc));
                i+=2;
             }
        } else {
            ret+= chr;
        }
    }
    return ret;
}
alert(UrlDecode(UrlEncode(&quot;&#35745;&#31639;&#26426;&quot;)));
&lt;/script&gt;</textarea><br />&#19979;&#38754;&#26159;&#21478;&#22806;&#19968;&#27573; vbs &#30340; UrlEncode<br /><textarea name='code' class='vb' cols='50'>function urlencode(vstrin) 
    dim i,strreturn,strSpecial 
    strSpecial = &quot; &lt;&gt;&quot;&quot;#%{}|^~[]`'&amp;?+&quot; 
    strreturn = &quot;&quot; 
    for i = 1 to len(vstrin) 
        thischr = mid(vstrin,i,1) 
        if abs(asc(thischr)) &lt; &amp;hff then 
            if instr(strSpecial,thischr)&gt;0 then 
                strreturn = strreturn &amp; &quot;%&quot; &amp; hex(asc(thischr)) 
            else 
                strreturn = strreturn &amp; thischr 
            end if 
        else 
            innercode = asc(thischr) 
            if innercode &lt; 0 then 
                innercode = innercode + &amp;h10000 
            end if 
            hight8 = innercode \ 256 '(innercode  and &amp;hff00)'   mod &amp;hff
            low8 = innercode and &amp;hff 
            strreturn = strreturn &amp; &quot;%&quot; &amp; hex(hight8) &amp;  &quot;%&quot; &amp; hex(low8) 
        end if 
    next 
    urlencode = strreturn 
end function 
document.write urlencode(&quot;&#20013;&#25991; &lt;&gt;&quot;&quot;#%{}|^~[]`'&amp;?+Abc&quot;) &amp; &quot;&lt;br&gt;&quot; &amp; urlencode(&quot;&#35745;&#31639;&#26426;&quot;) </textarea>]]></content><publish>2007-07-21 16:31:02</publish><update>2008-08-17 19:37:00</update><comment>0</comment><view>3487</view></article><comments/><previous id="130"><title>常用数据库JDBC连接写法</title></previous><next id="132"><title>郁闷，ArcGIS 装了不能用</title></next></content></panel></panels><modules><module id="4" sn="3" sys="true"><name>Category</name><title>日志分类</title></module><module id="6" sn="4" sys="true"><name>Archive</name><title>日志归档</title></module><module id="5" sn="5" sys="true"><name>User Panel</name><title>控制面板</title></module><module id="10" sn="6" sys="true"><name>Recent Article</name><title>最新日志</title></module><module id="8" sn="7" sys="true"><name>Search</name><title>查询搜索</title></module><module id="7" sn="8" sys="true"><name>Recent Comments</name><title>最新评论</title></module><module id="2" sn="9" sys="true"><name>Statistics</name><title>统计信息</title></module></modules><user><usn></usn><status>3</status><login>false</login></user></blog>
