atlanta Posted January 10, 2009 Share Posted January 10, 2009 Hi guys i need a little help i need to retrieve different parts of a url for use in my .htaccess file all help appreciated .. ok heres my example.. http://domain.com/firstpart/secondpart/ ok i need to retrieve firstpart in one group and secondpart in the second group.. i tried ^/(.*?)/(.*?)/$ but the first group selects everything! Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted January 10, 2009 Share Posted January 10, 2009 Here's my take: $str = parse_url('http://domain.com/firstpart/secondpart/'); $group = preg_split('#/#', $str['path'], -1, PREG_SPLIT_NO_EMPTY); echo '<pre>'.print_r($group, true); Output: Array ( [0] => firstpart [1] => secondpart ) When dealing with URLs, I like to personally use parse_url(), as it divides the url into organized components, and then simply deal with whatever component I need from there (which in this case happens to be the ['path'] part). Quote Link to comment Share on other sites More sharing options...
atlanta Posted January 10, 2009 Author Share Posted January 10, 2009 thanks nrg_alpha but i need the whole regex to do it becuase i will be using this for mod rewrite not php Quote Link to comment Share on other sites More sharing options...
corbin Posted January 10, 2009 Share Posted January 10, 2009 ~^([^/]+)/([^/]+)/?~ Quote Link to comment Share on other sites More sharing options...
.josh Posted January 10, 2009 Share Posted January 10, 2009 http://[^/]+/([^/]+)/([^/]+)/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.