1. The preg_filter function is used to perform a regular expression search and replace.
preg_filter() is equivalent to preg_replace(), but it only returns results that match the target.
grammar
mixed preg_filter ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )
Parameter description
$pattern: The pattern to search for. Can be a string or an array of strings.
$replacement: String or array of strings used for replacement.
$subject: The string or array of strings to search and replace.
$limit: Optional, the number of replacements for each pattern on each subject. The default is -1().
$count: Optional, the number of replacements completed.
2. The preg_replace_callback function performs a regular expression search and replaces it using a callback.
Except that you can specify a callback instead of replacement to calculate the replacement string, it is equivalent to preg_replace() in other aspects.
grammar
mixed preg_replace_callback ( mixed $pattern , callable $callback , mixed $subject [, int $limit = -1 [, int &$count ]] )
Parameter description
$pattern: The pattern to search for, which can be a string or an array of strings.
$callback: A callback function that is called every time a replacement is needed. The parameters obtained by the function when called are the results matched from the subject.
$subject: The target string or string array to be searched and replaced.
$limit: Optional, the number of substitutions for each subject string per pattern. The default is -1(system).
$count: Optional, the number of times the replacement is performed.
The above is the arrangement of PHP regular replacement functions. This article mainly introduces two types of functions. If you are interested, you can continue to expand on other functions.