In this tutorial, we are going to see how to replace a word in a string in PHP. You can use str_replace() function in PHP to replace all occurrences of a word in a string. In the following example, the word “google” is replaced with the word “StackHowTo”.
How to replace a word in a string in PHP
The str_replace() function is case sensitive. If you want to perform a case-insensitive match, you can use the str_ireplace() function.
<?php $str = 'Welcome to google.com'; echo str_replace("google", "waytolearnx", $str); ?>
Welcome to StackHowTo.comMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More