3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "My text has so much whitespace Plenty of spaces and tabs"; //Remove duplicate newlines $string = preg_replace("/[\n]*/", "\n", $string); //Preserves newlines while replacing the other whitspaces with single space var_export( preg_replace("/[ \t]*/", " ", $string) );

preferences:
27.25 ms | 405 KiB | 5 Q