I’m pretty stuck in here, so what I need is a function or, an idea to create a function, to work pretty the same way as mod_rewrite of Apache.
It is supposed to have as param a regexp, writtten for mod_rewrite, and the url. Should return an array of parameters extracted from it.
Here’s a short example of how it should work:
function rewrite($regexp, $url){
....
}
$params = rewrite('([^/]+)-([^/]+).html', 'Oval-Shape.html');
print_r($params);
The code above should print:
array(1=>Oval, 2=>Shape)
Yes,
RewriteRuleuses a perl compatible regular expression. That’s the same PHP does inpreg_match().A difference is, that in
ModRewriteyou can prefix it with a!to not match something.Another thing is, when you add the
NCflag, they are case in-sensitive. In a PHP regex this can be achieved by using theimodifier.So before you start re-invent the wheel, why not choose that function? It works like this:
And this is the output:
So
$params[1]is what you know as$1in .htacces and so on.