开发者

Get string from URL

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

ht开发者_StackOverflow中文版tp://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!


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] ;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜