php auto trim middle space code example Example: remove whitespace from string php $str = "\n\n\nHello World!\n\n\n"; echo "With trim: " . trim($str);