0

I had a little issue, i need to extract a string from the URL that looks like this:

http://www.myserver.com/category/firstcat/second-cat/

All my URLs has this structure, and I need to catch the "firstcat" string

I would appreciate your help!

Thanks so much!

2 Answers 2

3

If you're trying to do this on the current url the user is on, you'll need $_SERVER['REQUEST_URI']. That will show you the current uri open, in this case /category/firstcat/second-cat/.

Then use anything you prefer to parse the string and get to the element you want, for example:

$elms = explode('/', $uri) ;
$firstcat = $elms[2] ;
Sign up to request clarification or add additional context in comments.

Comments

1

Aren't you using mod_rewrite? Place a rule in your htaccess:

RewriteRule ([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/ ?cat=$1&subcat=$2&name=$3

And you'll have it ready in $_GET array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.