Jump to content

Recommended Posts

Posted

I've ported these two functions from PHP to AU3 to work with URLs.

Made them for those who work with libraries like HTTP.au3 (not the one I coded), that needs passing the server domain, path, etc., instead of the full URL.

Grab the lib here.

ParseURL( $sURL )

Parses the URL and splits it into defined parts. Returns an array:

  • [0] = Full URL (same as $sURL)
  • [1] = Protocol (i.e.: http, https, ftp, ws...)
  • [2] = Domain
  • [3] = Port (or null if not specified)
  • [4] = Path (or null if not specified)
  • [5] = Query string (everything after the ? - or null if not specified)

Example:

$aExample = ParseURL("https://google.com:8080/?name=doe")

MsgBox(0, "Test", "URL: " & $aExample[0] & @CRLF & _
                    "Protocol: " & $aExample[1] & @CRLF & _
                    "Domain: " & $aExample[2] & @CRLF & _
                    "Port: " & $aExample[3] & @CRLF & _
                    "Path: " & $aExample[4] & @CRLF & _
                    "Query string: " & $aExample[5])

 

ParseStr( $sStr )

Parses a query string (similar to the [5] of the previous function) and returns a multidimensional array, where:

  • [0][0] = number of variables found
  • [0][1] = ununsed
  • [1][0] = key name of the first variable
  • [1][1] = first variable value (already URL decoded)
  • [n][0] = key name of the nth variable
  • [n][1] = nth variable value (already URL decoded)

Example:

include <Array.au3> ; need only to do _ArrayDisplay, not needed by the lib

_ArrayDisplay(ParseStr("foo=bar&test=lol%20123"))

#cs
Result is:
[0][0] = 2
[0][1] = ununsed
[1][0] = foo
[1][1] = bar
[2][0] = test
[2][1] = lol 123
#ce

Feel free to fork! :)

My stuff

  Reveal hidden contents

 

Posted

Thanks for sharing. Seemingly works well ... thus far. :thumbsup:

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

Once again, thanks Jefrey.

I have now used your script in a project, found here.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

Glad to know it was useful for you, @TheSaint :) 

My stuff

  Reveal hidden contents

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...