Replacing Parts of Strings in PHP


Use str_replace() to replace all occurrences of a search string with a replacement string.

Source Code

$text = "The quick brown fox jumps over the lazy dog.";
$replaced = str_replace("brown", "red", $text);
echo $replaced; // Outputs: The quick red fox jumps over the lazy dog.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments