I've trying to make my own route class - and I've hot problem with parsing valid url's.
This is an example url: http://localhost/app/module/command/i15
And I need every element after slash / to be an additional element in array creating using preg_match in php.
So - for searching of numbers I've got: ([0-9]+) Searching strings that contains letters, signs like - or _ I've got ([^.]+) (here's the problem)
whole regexp looks like this:
(app)\/(module)\/([^.]+)\/i([0-9]+)
i want an array of 5 elements, something like that:
0 => app, 1=> module, 2 => command, 3 => i15
It will be more beauty if preg_match will return only something like that:
0 => app, 1=> module, 2 => command, 3 => 15
(without I as param identifier)
Can anyone quick help me with this ? I stuck 2 days in that, and can't find right solution.
EDIT: I've got some regexp predefined like:
/app/contacts/list => (app)\/(contacts)\/([^.]+)
/app/contacts/edit/i15 => (app)\/(contacts)\/([^.]+)\/i([\d]+)
/app/contacts/view/i15-c2 => (app)\/(contacts)\/([^.]+)\/i([\d]+)-c([\d]+)
And for all of those I prepare different regexp like above. Problem stars when I need to parse something between:
/app/contacts/preview/random-name/i15-c2
or
/app/contacts/preview/random-name-i15-c2
([^.]+) catches also \ (slash) - and in above first example this slash broke whole regexp :-(
EDIT SECOND TIME :-)
I've got some predefined regexps for some paths. Lets have a look:
$regexp = [
[0 => '(app)\/([^/]+)'],
[1 => '(app)\/([^/]+)\/i([0-9]+)']
];
Next i check current url and match the best result - I know what I want, but php doesn't know what user select so:
if I enter url with path:
app/username/i15
System shows me that $regexp[0] is best result - what it is not true, because $regexp[1] are the best.
I hope this explains my problem.