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 manual page for preg_filter:
preg_filter() is identical to preg_replace() except it only returns the (possibly transformed) subjects where there was a match. For details about how this function works, read the preg_replace() documentation.
From the manual page for preg_replace:
$0 refers to the text matched by the whole pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With