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