Home / PHP Tips Generated By ChatGPT / 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!