str_replace() Function | Replace any Text in String in PHP

str_replace() function is used to replace text in a string. Its first parameter takes the text to find in a given string, write text to replace the first parameter text, and the third parameter takes the string to find and replace.

Syntax-

str_replace(search, replace, subject);

Example-

<?php

$text = "HTML stands for Hypetext Preprocessor.";
$new_string = str_replace("HTML", "PHP", $text);
echo $new_string;

?>

Leave a Comment