The preg_replace function performs a regular expression search and replace.
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )
Search the part of subject that matches pattern and replace it with replacement.
Parameter description:
$pattern: The pattern to search for, which can be a string or an array of strings.
$replacement: String or array of strings to use for replacement.
$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() returns an array, otherwise it returns a string.
If a match is found, the replaced subject is returned, otherwise the unchanged subject is returned. If an error occurs, NULL is returned.
The execution result is as follows:
codercto 123,456
The execution result is as follows:
codercto
The execution result is as follows:
The bear black slow jumped over the lazy dog.
The execution result is as follows:
xp***to3