PHP Program to replace a word in a string using str_replace()

bookmark

<?php
    $str= 'Sayesaha';
    
    // message to be printed
    $newstr = 'welcome '. $str . ' to learn about PHP language. We are delighted to have you '.$str;
    
    // printing message 
    echo ($newstr."\n");
    
    // changing the name
    $str1= 'Sayesha';
    echo str_replace($str, $str1 , $newstr);
?>


Output


welcome Sayesaha to learn about PHP language. We are delighted to have you Sayesaha
welcome Sayesha to learn about PHP language. We are delighted to have you Sayesha