PHP program to demonstrate the regular expression to replace the substring within the string
belongs to collection: PHP Regular Expressions Programs
All Answers
total answers (1)
belongs to collection: PHP Regular Expressions Programs
total answers (1)
Program/Source Code:
The source code to demonstrate the regular expression to replace the substring within the string is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a string variable $str, which is initialized with "Welcome to India". After that, we used 'i' in the pattern to search case insensitive substring in the specified string. Here, we used the preg_replace() function to replace the substring within the string and return the updated string that will be assigned to the variable $str1 and printed on the webpage using the print() function.
need an explanation for this answer? contact us directly to get an explanation for this answer