I'm trying to do a simple preg_match_all
but don't get it running.
Following the code:
$regex= "get-/my/test/(?<{id1}>.*)/foo/(?<{f11}>.*)";
$template = "get-/my/test/hallo/foo/awwww123";
$match = preg_match_all("/".$regex."/",$template, $matches, PREG_SET_ORDER);
var_dump($match);
var_dump($matches);
Executing the code I get the following error message:
E_WARNING : type 2 -- preg_match_all(): Unknown modifier 'y' -- at line 5
What I'm doing wrong?
My expectation is, that $match
is true
and $matches
include the groups with names.
Update
Ok, I added the preg_quote
but why is the following code not matching?
$regex= "get-/my/test/(?<{if1}>.*)/foo/(?<{tf4}>.*)";
$template = "get-/my/test/hallo/foo/werner12";
$regex = preg_quote($regex, "/");
$match = preg_match_all("|".$regex."|",$template, $matches, PREG_SET_ORDER);
var_dump($match);
var_dump($matches);