3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = "ABCDE \t\n\r\x0B\x0C\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", "\x0C", "\0"), '', $string); var_dump($array);
based on Ndcik
Output for 4.3.0 - 4.3.2, 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 4.3.3 - 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" }