• PHP Video Tutorials

PHP - Function ereg_replace()


string ereg_replace (string pattern, string replacement, string originalstring);

Definition and Usage

The ereg_replace() function searches for string specified by pattern and replaces pattern with replacement if found. The ereg_replace() function operates under the same premises as ereg(), except that the functionality is extended to finding and replacing pattern instead of simply locating it.

Like ereg(), ereg_replace() is case sensitive.

Return Value

  • After the replacement has occurred, the modified string will be returned.

  • If no matches are found, the string will remain unchanged.


Following is the piece of code, copy and paste this code into a file and verify the result.

   $copy_date = "Copyright 1999";
   $copy_date = ereg_replace("([0-9]+)", "2000", $copy_date);
   print $copy_date;

This will produce the following result −

Ereg Replace