Home / PHP Tips Generated By ChatGPT / Trimming Whitespace from Strings in PHP Remove whitespace from the beginning and end of a string with trim(). Source Code $text = " Hello, World! "; $trimmed = trim($text); echo $trimmed;