3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = "ABCDE \t\n\r\x0B\f\0"; $array = array(); $array[] = trim($string); $array[] = preg_replace('/\s+/', '', $string); $array[] = preg_replace('/\s\s+/', '', $string); $array[] = trim(preg_replace('/[\s\t\n\r\s]+/', '', $string)); $array[] = preg_replace('/~\x{00a0}~siu/', '', $string); $array[] = str_replace(array(" ", "\t", "\n", "\r", "\x0B", "\f", "\0"), '', $string); var_dump($array);
based on dKR6X
Output for 5.4.41 - 7.1.0
array(6) { [0]=> string(11) "ABCDE " [1]=> string(6) "ABCDE" [2]=> string(6) "ABCDE" [3]=> string(5) "ABCDE" [4]=> string(12) "ABCDE " [5]=> string(5) "ABCDE" }
Output for 5.2.5 - 5.4.40
array(6) { [0]=> string(11) "ABCDE " [1]=> string(7) "ABCDE " [2]=> string(8) "ABCDE " [3]=> string(5) "ABCDE" [4]=> string(12) "ABCDE " [5]=> string(5) "ABCDE" }
Output for 4.3.3 - 5.2.4
array(6) { [0]=> string(12) "ABCDE \f" [1]=> string(9) "ABCDE \f" [2]=> string(9) "ABCDE \f" [3]=> string(8) "ABCDE \f" [4]=> string(13) "ABCDE \f" [5]=> string(5) "ABCDE" }
Output for 4.3.0 - 4.3.2
array(6) { [0]=> string(12) "ABCDE \f" [1]=> string(8) "ABCDE\f" [2]=> string(8) "ABCDE\f" [3]=> string(8) "ABCDE \f" [4]=> string(13) "ABCDE \f" [5]=> string(5) "ABCDE" }