3月302015
精典小巧的Url转码
Func UrlEnc($Sz_url)
Local $str=StringTrimLeft(StringToBinary($Sz_url,1),2)
Local $ret
For $i=1 to StringLen($str) Step 2
$ret &='%' & StringMid($str,$i,2)
Next
Return $ret
EndFunc```
<p>
<br />
</p>
<p>
详细一点的
</p>
<p>
<br />
</p>
<p>
<br />
</p>
```<code class="language-autoit hljs">#include-once
;===============================================================================
; _UnicodeURLEncode()
; Description: : Encodes an unicode string to be URL-friendly
; Parameter(s): : $UnicodeURL - The Unicode String to Encode
; Return Value(s): : The URL encoded string
; Author(s): : Dhilip89
; Note(s): : -
;
;===============================================================================
Func _UnicodeURLEncode($UnicodeURL)
$UnicodeBinary = StringToBinary ($UnicodeURL, 4)
$UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
$UnicodeBinaryLength = StringLen($UnicodeBinary2)
Local $EncodedString
For $i = 1 To $UnicodeBinaryLength Step 2
$UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then
$EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
Else
$EncodedString &= '%' & $UnicodeBinaryChar
EndIf
Next
Return $EncodedString
EndFunc ;==>_UnicodeURLEncode
;===============================================================================
; _UnicodeURLDecode()
; Description: : Tranlates a URL-friendly string to a normal string
; Parameter(s): : $toDecode - The URL-friendly string to decode
; Return Value(s): : The URL decoded string
; Author(s): : nfwu, Dhilip89
; Note(s): : Modified from _URLDecode() that's only support non-unicode.
;
;===============================================================================
Func _UnicodeURLDecode($toDecode)
Local $strChar = "", $iOne, $iTwo
Local $aryHex = StringSplit($toDecode, "")
For $i = 1 To $aryHex[0]
If $aryHex[$i] = "%" Then
$i = $i + 1
$iOne = $aryHex[$i]
$i = $i + 1
$iTwo = $aryHex[$i]
$strChar = $strChar & Chr(Dec($iOne & $iTwo))
Else
$strChar = $strChar & $aryHex[$i]
EndIf
Next
$Process = StringToBinary (StringReplace($strChar, "+", " "))
$DecodedString = BinaryToString ($Process, 4)
Return $DecodedString
EndFunc ;==>_UnicodeURLDecode
#endregion```
<p>
<br />
</p>
<p>
新增加一个方式 2018-001-23
</p>
<p>
<br />
</p>
<p>
```<code class="language-autoit hljs">;JS 转码
Global $oScript = ObjCreate("MSScriptControl.ScriptControl.1")
With $oScript
.language = "JavaScript"
.Timeout = -1
EndWith
Func encodeURIComponent($sStr) ;URI编码
$oScript.Reset()
Return $oScript.Run("encodeURIComponent", $sStr)
EndFunc ;==>encodeURIComponent
Func decodeURIComponent($sStr) ;URI解码
$oScript.Reset()
Return $oScript.Run("decodeURIComponent", $sStr)
EndFunc ;==>decodeURIComponent
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!