Replacing Substrings in a String in PHP


Search for and replace a substring within a string using str_replace().

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