nfwu Posted March 18, 2006 Posted March 18, 2006 (edited) expandcollapse popup;=============================================================================== ; _URLEncode() ; Description: : Encodes a string to be URL-friendly ; Parameter(s): : $toEncode - The String to Encode ; : $encodeType = 0 - Practical Encoding (Encode only what is necessary) ; : = 1 - Encode everything ; : = 2 - RFC 1738 Encoding - http://www.ietf.org/rfc/rfc1738.txt ; Return Value(s): : The URL encoded string ; Author(s): : nfwu ; Note(s): : - ; ;=============================================================================== Func _URLEncode($toEncode, $encodeType = 0) Local $strHex = "", $iDec Local $aryChar = StringSplit($toEncode, "") If $encodeType = 1 Then;;Encode EVERYTHING For $i = 1 To $aryChar[0] $strHex = $strHex & "%" & Hex(Asc($aryChar[$i]), 2) Next Return $strHex ElseIf $encodeType = 0 Then;;Practical Encoding For $i = 1 To $aryChar[0] $iDec = Asc($aryChar[$i]) if $iDec <= 32 Or $iDec = 37 Then $strHex = $strHex & "%" & Hex($iDec, 2) Else $strHex = $strHex & $aryChar[$i] EndIf Next Return $strHex ElseIf $encodeType = 2 Then;;RFC 1738 Encoding For $i = 1 To $aryChar[0] If Not StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", $aryChar[$i]) Then $strHex = $strHex & "%" & Hex(Asc($aryChar[$i]), 2) Else $strHex = $strHex & $aryChar[$i] EndIf Next Return $strHex EndIf EndFunc ;=============================================================================== ; _URLDecode() ; 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 ; Note(s): : - ; ;=============================================================================== Func _URLDecode($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 Return StringReplace($strChar, "+", " ") EndFunc Example: ;;;;;;;;;;;;;;;;;;;;; ;;;;;;;EXAMPLE;;;;;;; ;;;;;;;;;;;;;;;;;;;;; $testString = "This is a test. By nfwu. @CRLF here:"&@CRLF&"~!@#$%^&*()_+`-=\|';:""[]{},.<>/?" MsgBox(0, "This is the string we'll use to test:", $testString) $string0 = _URLEncode($testString, 0) $string1 = _URLEncode($testString, 1) $string2 = _URLEncode($testString, 2) MsgBox(0, "ENCODED STRINGS", _ "0(Practical): "&@CRLF&$string0&@CRLF&@CRLF& _ "1(Evereything): "&@CRLF&$string1&@CRLF&@CRLF& _ "2(RFC 1738): "&@CRLF&$string2 _ ) $string0 = _URLDecode($string0) $string1 = _URLDecode($string1) $string2 = _URLDecode($string2) MsgBox(0, "DECODED STRINGS", _ "0(Practical): "&@CRLF&$string0&@CRLF&@CRLF& _ "1(Evereything): "&@CRLF&$string1&@CRLF&@CRLF& _ "2(RFC 1738): "&@CRLF&$string2 _ ) What do you think? #) EDIT: thanks to the RTF poster, i had to edit it... Edited March 18, 2006 by nfwu Klexur 1 TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
Stumpii Posted September 16, 2006 Posted September 16, 2006 Would like to sneak in a little thank you into the multitude of replies to your post Anyway, this is just what I was looking for. I will give it a try. Thank you. Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.
JonathanChan Posted June 7, 2007 Posted June 7, 2007 Great script! Thanks! More powerful than the one the other guy wrote!
GtaSpider Posted July 26, 2008 Posted July 26, 2008 Is this Thing working good?Why is it not in autoit ?Uhm? This is AutoIt^^ www.AutoIt.de - Moderator of the German AutoIt Forum
oren Posted July 26, 2008 Posted July 26, 2008 No i meant why it is not a defult class that came with autoit defult from the website... anyway... Are there more classes like this? Becouase this class is not complate
James Posted July 26, 2008 Posted July 26, 2008 No i meant why it is not a defult class that came with autoit defult from the website...anyway... Are there more classes like this? Becouase this class is not complateYou mean includes. And this topic is 2 years old. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now