Reputation: 1884
Just simple question (I've google this but not found the answer). What's the meaning of ?P in this statement :
preg_match('/^posts\/(?P<id>\d+)$/', $url, $matches);
Upvotes: 1
Views: 112
Reputation: 100175
It captures the match of id into the backreference "<name>" which is <id> in this case. Check this link for more clearification: http://php.net/manual/en/function.preg-match.php
Upvotes: 0
Reputation: 141839
(?P<name>patt)
is a named subpattern. It means that you can access the match for that subpattern by looking in $matches['id']
as well as the usual $matches[1]
.
Upvotes: 1