Php Preg_Replace_Callback
# PHP preg_replace_callback() Function
[PHP Regular Expressions (PCRE)](#)
The preg_replace_callback function performs a regular expression search and uses a callback for replacement.
### Syntax
mixed preg_replace_callback ( mixed $pattern , callable $callback , mixed $subject [, int $limit = -1 [, int &$count ]] )
This function behaves similarly to preg_replace(), except that instead of a replacement string, a callback is specified for the replacement calculation.
Parameter Description:
* $pattern: The pattern to search for. Can be a string or an array of strings.
* $callback: A callback function that is called for each match. The function receives the matched results from the subject as parameters.
* $subject: The target string or array of strings to search and replace.
* $limit: Optional. The maximum number of replacements for each pattern in each subject string. Default is -1 (no limit).
* $count: Optional. The number of replacements performed.
### Return Value
If subject is an array, preg_replace_callback() returns an array; otherwise, it returns a string. Returns NULL on error.
If a match is found, the replaced target string (or array of strings) is returned; otherwise, the subject is returned unchanged.
### Example
## Example 1
The execution result is as follows:
April fools day is 04/01/2003Last christmas was 12/24/2002
[PHP Regular Expressions (PCRE)](#)
YouTip