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

Date Published: 02/02/2021 Published By: JaiSchool

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

Syntax-

str_replace(search, replace, subject);

Example-

<?php

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

?>

Publish A Comment

Leave a Reply

Your email address will not be published.