How do you query the data after the 4th slash in a URL?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do you query the data after the 4th slash in a URL?

Post by simonmlewis »

I'm sure I have asked this before, as I know I have done it - but I cannot recall where I did this.

So if the URL is:
http://www.site.com/product/445/xl/335/ ... /red-shirt

I was to know if "product" appears after that first main slash.
And then I want to query the string after the sixth slash.

If I can find the first slash and put that word into a query, or find the sixth and put that digit into a variable, I am sorted.

As I say, I've done this but no idea where. Either Explode or Pregmatch, but not sure how I count the slashes.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you query the data after the 4th slash in a URL?

Post by Celauran »

Explode is probably the easier of those two options. Which index you use from the resulting array depends on whether or not you're passing in the complete URL (due to the ://). Explode and print_r the result and you'll see which key you want.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you query the data after the 4th slash in a URL?

Post by simonmlewis »

Cool, yeah I sussed it. Any more news on the other thread about using the javascript twice "focus"?

viewtopic.php?f=13&t=140273

Tho you wasn't the last contributor.
At the moment we are running the mobile part with just one image, as we cannot see how to do it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply