preg_filter
Function • Params and return types changed in PHP 8.0
Perform a regular expression search and replace.
preg_filter Function synopsis
preg_filter(
array|string $pattern,
array|string $replacement,
array|string $subject,
int $limit = -1,
&$count = null
): array|string|null
Parameters
$pattern
Typearray|string
$replacement
Typearray|string
$subject
Typearray|string
$limit
OptionalTypeintDefault value-1
$count
Passed by reference, OptionalDefault valuenull
Note that the parameter
$countis passed by reference, and contains additional/updated context data that may be useful.
Return value
Typearray|string|null
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.
Changes to the preg_filter Function
PHP 8.0
- Return type added:
array|string|null - Parameter name of parameter #1 changed:
$regexto$pattern - Parameter type added for parameter #1 (
$pattern):array|string - Parameter name of parameter #2 changed:
$replaceto$replacement - Parameter type added for parameter #2 (
$replacement):array|string - Parameter type added for parameter #3 (
$subject):array|string - Parameter type added for parameter #4 (
$limit):int - Parameter default value added for position #4 (
$limit):-1 - Parameter default value added for position #5 (
$count):null
preg_filter(
- $regex,
+ array|string $pattern,
- $replace,
+ array|string $replacement,
- $subject,
+ array|string $subject,
- $limit,
+ int $limit = -1,
- &$count
+ &$count = null
- )
+ ): array|string|null preg_filter Function Availability
preg_filter Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |