Loading, please wait...

A to Z Full Forms and Acronyms

How to demonstrate the regular expression to replace the substring within the string in PHP | PHP program

Feb 28, 2022 PHP, 1475 Views
How to demonstrate the regular expression to replace the substring within the string in PHP | PHP program

How to demonstrate the regular expression to replace the substring within the string in PHP | PHP program

We will demonstrate the regular expression to replace a specified substring within the string using the preg_replace() function.

<?php



$str = "Welcome to India";
$pattern = "/india/i";

$str1 = preg_replace($pattern, "USA", $str);

print ($str1);
?>
A to Z Full Forms and Acronyms