The preg_replace_callback function performs a regular expression search and replaces it using a callback.
mixed preg_replace_callback ( mixed $pattern , callable $callback , mixed $subject [, int $limit = -1 [, int &$count ]] )
The behavior of this function is equivalent to preg_replace() except that you can specify a callback instead of replacement to calculate the replacement string.
Parameter description:
$pattern: The pattern to search for, which can be a string or an array of strings.
$callback: A callback function that is called every time a replacement is needed. The parameters obtained by the function when called are the results matched from the subject.
$subject: The target string or string array to be searched and replaced.
$limit: Optional, the maximum number of substitutions for each subject string per pattern. The default is -1 (no limit).
$count: Optional, the number of times the replacement is performed.
If subject is an array, preg_replace_callback() returns an array, otherwise it returns a string. Returns NULL when an error occurs.
If a match is found, the replaced target string (or string array) is returned. Otherwise, the subject will be returned unchanged.
The execution result is as follows:
April fools day is 04/01/2003Last christmas was 12/24/2002