PHP & Apache - parse mod_rewrite url?

$uri = 'about/us'; list($page, $action) = explode('/', $uri) If you need more than two, simply remove the list: $pagePath = explode('/', $uri) But, if you insist on using regular expressions, this will do: $regex = '#(?P. *)/(?P. *) However, it offers you nothing special except that $matches will now contain $matches'page' and $matches'action' but if you really need it, youcan use list() as shown above Using the explode function would make me evaluate the uri segments later in the code, wich I'd like to avoid Instead of making sure the page is valid by it's character set, why not compile a list of valid pages lookup table and just use php's in_array which is much faster than a regular expression?

Extracting the URL segments into an array will allow you to have multi-dimension arrays validated in no time.

$uri = 'about/us'; list($page, $action) = explode('/', $uri); If you need more than two, simply remove the list: $pagePath = explode('/', $uri); But, if you insist on using regular expressions, this will do: $regex = '#(?P. *)/(?P. *)#'; However, it offers you nothing special except that $matches will now contain $matches'page' and $matches'action' - but if you really need it, youcan use list() as shown above.

Using the explode function would make me evaluate the uri segments later in the code, wich I'd like to avoid Instead of making sure the page is valid by it's character set, why not compile a list of valid pages lookup table and just use php's in_array which is much faster than a regular expression? Extracting the URL segments into an array will allow you to have multi-dimension arrays validated in no time.

It would work if the situation was always easy, but it ain't. So I really need to use regular expressions. – yoda Feb 6 '10 at 20:42 Care to explain why?

URL will always have '/'s and this seems like a suitable solution. I can't see why regular expressions to manually split the URL entry is necessary. Is the question missing info, maybe?

– LiraNuna Feb 6 '10 at 20:45 +1 regex is expensive! – Sepehr Lajevardi Feb 6 '10 at 20:56 you're right, I'll update the question – yoda Feb 6 '10 at 21:02 I ended up figuring out what I was missing about regex, but thanks anyway! ;) – yoda Feb 6 '10 at 22:01.

I think the regex needs to be surrounded by a symbol; for example '@(page(/))@'. See the examples in php.net/preg_match.

If you absolutely must use a regex for some reason try this: $uri = 'about/us'; $regex = '~(?^/+)/(?. +)~'; var_dump($matches); Which outputs: array(5) { 0=> string(8) "about/us" "path"=> string(5) "about" 1=> string(5) "about" "action"=> string(2) "us" 2=> string(2) "us" } However this will only work when the path component only goes down one level!

I have my server's apache configured to redirect every request into index. Now I need to parse the url in order to determine if each route exists and what to expect from it, so I can set a database table to save the routes and so my clients can edit their routes as they like them to be. Thing is, I'm not able to do the parsing so far.

It always shows up that echo message.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions