php remove spaces from string

PHP
$str = "\n\n\nHello World!\n\n\n";
echo "With trim: " . trim($str);
Source

Also in PHP: