Replacing Substrings in Strings in PHP


Use str_replace() to replace occurrences of a substring within a string.

Source Code

$text = "Hello, World!";
$newText = str_replace("World", "PHP", $text);
echo $newText; // Outputs: Hello, PHP!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments