3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ ", One ,, ,,", ", Two , Three", "Four, Five ", " Six,Seven, ", " ,Eight ,Nine , , , , Ten ,", ]; foreach ($tests as $test) { var_export( preg_replace('/[, ]+/', ', ', trim($test, ', ')) ); echo "\n"; }

preferences:
30.27 ms | 410 KiB | 6 Q