3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = "ABCDE \t\n\r\x0B\x0C\0\x20\x0e\x20\x0f"; $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", "\x0C", "\0"), '', $string); var_dump($array);
based on Ec5e8
Output for 5.4.41 - 7.1.0
array(6) { [0]=> string(16) "ABCDE  " [1]=> string(8) "ABCDE" [2]=> string(10) "ABCDE  " [3]=> string(8) "ABCDE" [4]=> string(16) "ABCDE  " [5]=> string(7) "ABCDE" }
Output for 4.3.3 - 5.4.40
array(6) { [0]=> string(16) "ABCDE  " [1]=> string(9) "ABCDE " [2]=> string(12) "ABCDE  " [3]=> string(9) "ABCDE " [4]=> string(16) "ABCDE  " [5]=> string(7) "ABCDE" }
Output for 4.3.0 - 4.3.2
array(6) { [0]=> string(16) "ABCDE  " [1]=> string(8) "ABCDE" [2]=> string(10) "ABCDE  " [3]=> string(9) "ABCDE " [4]=> string(16) "ABCDE  " [5]=> string(7) "ABCDE" }