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

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.

Related Functions

Example of preg_filter

Show all examples for preg_filter

PHP Version:


Function preg_filter:

Regular Expressions (Perl-Compatible) Functions

Most used PHP functions