Jump to content



Photo

_urlencode() / _urldecode()


  • Please log in to reply
6 replies to this topic

#1 nfwu

nfwu

    I'm not active on these forums

  • Active Members
  • PipPipPipPipPipPip
  • 1,234 posts

Posted 18 March 2006 - 11:09 AM

Plain Text         
;=============================================================================== ; _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 - <a href='http://www.ietf.org/rfc/rfc1738.txt' class='bbc_url' title='External link' rel='nofollow external'>http://www.ietf.org/rfc/rfc1738.txt</a> ; 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 by nfwu, 18 March 2006 - 11:11 AM.

  • Klexur likes this







#2 Stumpii

Stumpii

    Mr. Stumpii

  • Active Members
  • PipPipPipPipPipPip
  • 465 posts

Posted 16 September 2006 - 12:42 AM

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.

#3 JonathanChan

JonathanChan

    Seeker

  • Active Members
  • 40 posts

Posted 07 June 2007 - 06:20 PM

Great script! Thanks! More powerful than the one the other guy wrote!

#4 oren

oren

    Adventurer

  • Active Members
  • PipPip
  • 145 posts

Posted 26 July 2008 - 04:43 PM

Is this Thing working good?
Why is it not in autoit ?

#5 GtaSpider

GtaSpider

    Polymath

  • Active Members
  • PipPipPipPip
  • 209 posts

Posted 26 July 2008 - 05:57 PM

Is this Thing working good?
Why is it not in autoit ?


Uhm? This is AutoIt^^

www.AutoIt.de - Moderator of The German AutoIt FroumPosted Image


#6 oren

oren

    Adventurer

  • Active Members
  • PipPip
  • 145 posts

Posted 26 July 2008 - 06:12 PM

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

#7 James

James

    jbrooksuk

  • MVPs
  • 9,470 posts

Posted 26 July 2008 - 07:52 PM

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

You mean includes. And this topic is 2 years old.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users