Using preg_replace()

The preg_replace() function will replace all of the matches of the pattern in a string with another string.

<?php
$str = "Visit Microsoft!";
$pattern = "/microsoft/i";
echo preg_replace($pattern, "codeapka", $str); // Outputs "Visit codeapka!"
?>
Scroll to Top