Escape加密函数
<h1>PHP中Escape加密函数</h1>
<pre><code class="language-php">function escape($str) {
$sublen = strlen ( $str );
$retrunString = "";
for($i = 0; $i < $sublen; $i ++) {
if (ord ( $str [$i] ) >= 127) {
$tmpString = bin2hex ( iconv ( "gb2312", "ucs-2", substr ( $str, $i, 2 ) ) );
$retrunString .= "%u" . $tmpString;
$i ++;
} else {
$retrunString .= "%" . dechex ( ord ( $str [$i] ) );
}
}
return $retrunString;
}</code></pre>
<h1>ASP中Escape加密函数</h1>
<pre><code class="language-asp">Function Escape(str)
dim i,s,c,a
s=""
For i=1 to Len(str)
c=Mid(str,i,1)
a=ASCW(c)
If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
s = s & c
ElseIf InStr("@*_+-./",c)>0 Then
s = s & c
ElseIf a>0 and a<16 Then
s = s & "%0" & Hex(a)
ElseIf a>=16 and a<256 Then
s = s & "%" & Hex(a)
Else
s = s & "%u" & Hex(a)
End If
Next
Escape = s
End Function</code></pre>
<h1>其他语言的Escape加密函数请自行处理</h1>
<p><strong>参照加密结果:</strong>【你好】加密后为【%u4F60%u597D】</p>