Phppreg_filter performs a regular expression search and replacement. Preg_filter (PHP55.3.0) preg_filter-execute a regular expression to search for and replace mixedpreg_filter (mixed $ pattern, mixed $ replacement, mixed $ subject [, int $ limit-1 [, preg_filter
(PHP 5> = 5.3.0)
Preg_filter-execute a regular expression to search and replace
Mixed preg_filter (mixed $ pattern, mixed $ replacement, mixed $ subject [, int $ limit =-1 [, int & $ count])
Preg_filter () is equivalent to preg_replace () except that it only returns (possibly converted) results that match the target. For more information about how this function works, see preg_replace.
Return value
If the subject is an array, an array is returned. Otherwise, a string is returned.
If no match is found or an error occurs, an empty array is returned when the subject is an array. otherwise, NULL is returned.
Example
Example #1 compare preg_filter () and preg_replace ()
The code is as follows:
$ Subject = array ('1', 'A', '2', 'B', '3', 'A', 'B', '4 ');
$ Pattern = array ('/\ d/', '/[a-z]/', '/[1a]/');
$ Replace = array ('A: $ 0', 'B: $ 0', 'C: $0 ');
Echo "preg_filter returns \ n ";
Print_r (preg_filter ($ pattern, $ replace, $ subject ));
Echo "preg_replace returns \ n ";
Print_r (preg_replace ($ pattern, $ replace, $ subject ));
?>
The above routine will output:
The code is as follows:
Preg_filter returns
Array
(
[0] => A: C: 1
[1] => B: C:
[2] => A: 2
[3] => B: B
[4] => A: 3
[7] => A: 4
)
Preg_replace returns
Array
(
[0] => A: C: 1
[1] => B: C:
[2] => A: 2
[3] => B: B
[4] => A: 3
[5] =>
[6] => B
[7] => A: 4
)
- PCRE Patterns
- Preg_replace ()-execute a regular expression to search and replace
- Preg_replace_callback ()-execute a regular expression search and use a callback to replace
- Preg_grep ()-returns array entries in matching mode
- Preg_last_error ()-returns the error code generated by the last PCRE regular execution.
Http://www.bkjia.com/PHPjc/325093.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325093.htmlTechArticlepreg_filter (PHP 5 = 5.3.0) preg_filter-execute a regular expression to search and replace mixed preg_filter (mixed $ pattern, mixed $ replacement, mixed $ subject [, int $ limit =-1 [,...