preg_filter

FunctionParams and return types changed in PHP 8.0

Perform a regular expression search and replace.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

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 $count is 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: $regex to $pattern
  • Parameter type added for parameter #1 ($pattern): array|string
  • Parameter name of parameter #2 changed: $replace to $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

PHP VersionAvailability
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