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