Skip to content

Searching and Replacing

Searching and replacing allows modifying text based on patterns.

Functions include:

  • str_replace()
  • preg_replace()
$text = "I like cats";
echo str_replace("cats", "dogs", $text);
$text = "Version 123";
echo preg_replace("/[0-9]+/", "X", $text);