preg_filter
PHP 5 >= 5.3.0, PHP 7, PHP 8
preg_filter - Perform a regular expression search and replace
preg_filter(
string|array$pattern,
string|array$replacement,
string|array$subject,
[int$limit = -1],
[intcount = null]
): string|array|null
string|array$pattern,
string|array$replacement,
string|array$subject,
[int$limit = -1],
[int
): string|array|null
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.
Parameters
Parameters are described in the documentation for preg_replace.
Return Values
Returns an array if the subject parameter is an array, or a string otherwise.
If no matches are found or an error occurred, an empty array is returned when subject is an array or null otherwise.
Exceptions and Errors
If the regex pattern passed does not compile to a valid regex, an E_WARNING is emitted.