preg_replace

PHP 4, PHP 5, PHP 7, PHP 8
preg_replace - Perform a regular expression search and replace

Example #1 Using backreferences followed by numeric literals

Result: April1,2003

Example #2 Using indexed arrays with preg_replace

Result: The bear black slow jumps over the lazy dog.

Example #3 Replacing several values

Result: $startDate = 5/27/1999

Example #4 Strip whitespace


Example #5 Using the <span class='function-parameter'>count</span> parameter

Result: xp***to 3


Example #6 of preg_replace



Function preg_replace:

Regular Expressions (Perl-Compatible) Functions

Most used PHP functions