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! Link to comment https://forums.phpfreaks.com/topic/140246-regex-help/ 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). Link to comment https://forums.phpfreaks.com/topic/140246-regex-help/#findComment-733858 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 Link to comment https://forums.phpfreaks.com/topic/140246-regex-help/#findComment-734097 Share on other sites More sharing options...
corbin Posted January 10, 2009 Share Posted January 10, 2009 ~^([^/]+)/([^/]+)/?~ Link to comment https://forums.phpfreaks.com/topic/140246-regex-help/#findComment-734172 Share on other sites More sharing options...
.josh Posted January 10, 2009 Share Posted January 10, 2009 http://[^/]+/([^/]+)/([^/]+)/ Link to comment https://forums.phpfreaks.com/topic/140246-regex-help/#findComment-734176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.