I read a documentation of preg_filter
function it is look as follows. This is from php.net site.
$subject = array('1', 'a', '2', 'b', '3', 'A', 'B', '4');
$pattern = array('/\d/', '/[a-z]/', '/[1a]/');
$replace = array('A:$0', 'B:$0', 'C:$0');
print_r(preg_filter($pattern, $replace, $subject));
Here in the array of $replace some variables available like this - $0
When I try this it is returning the value was available before replace.
Is it a common variable on PHP or is it only available for PCRE functions? And i seen $1
, $2
, $3
... also in some articles.
Normally we can't have variables starting with numbers.
So can any one explain about this function and variable?
$0
represents the entire part of the string that matches the pattern.$1
and so on represent the subpatterns.From the PHP manual on
preg_replace
- http://php.net/manual/en/function.preg-replace.php:From the manual page for
preg_filter
:From the manual page for
preg_replace
: