Ok lets say I have a URL
example.com/hello/world/20111020 (with or without the trailing slash). What I would like to do is strip from the url the domain example.com. and then break the hello world 20111020 into an array. But my other problem is. Sometimes the URL has no /hello/world/20111020 or just /hello/ so I need to first determine if there is anything after example.com if there not, then do nothing as obviously there's nothing to work with. However if there is something there for each / I need to add it to this array in order. So I can work with the array[0] and know it was hello.
I tried something a couple days back but was running into issues with trailing slashes it kept breaking the script, I unfortunately abandoned that idea. And today I am looking for fresh ideas.
For parsing URLs, one different approach can be using anchor DOM object.
I have created the following regular expression for URLs
It has been written for MySql - I am sure with a bit of fiddling you can get it you work for your needs.
BTW - I took the idea from an RFC - The number escapes me at this moment
You can use the jQuery-URL-Parser plugin:
In your case you'd probably want to use
segment()
:This should work
Now
url_parts
will point to the array["hello", "world", "20111020"]
.