In this tutorial, we are going to see how to replace part of a string in PHP. You can use PHP’s str_replace() function to find and replace any part of a string with another string. In the following example, the “best website” substring of the $str string is replaced with the “great platform” string.
How to replace part of a string in PHP
<?php $str = "Welcom to StackHowTo, it is the best website for learning"; // Display the replaced string echo str_replace("best website", "great platform", $str); ?>
Welcom to StackHowTo, it is the great platform for learning