3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "\tA\t B \tC \t D "; var_export( [ 'input' => $string, 'space, no flag' => preg_split('~ +~', $string), 'space, flag' => preg_split('~ +~', $string, -1, PREG_SPLIT_NO_EMPTY), 'tab, no flag' => preg_split('~\t+~', $string), 'tab, flag' => preg_split('~\t+~', $string, -1, PREG_SPLIT_NO_EMPTY), 'whitespace, no flag' => preg_split('~\s+~', $string), 'whitespace, flag' => preg_split('~\s+~', $string, -1, PREG_SPLIT_NO_EMPTY), 'tab&space, no flag' => preg_split('~[\t ]+~', $string), 'tab&space, flag' => preg_split('~[\t ]+~', $string, -1, PREG_SPLIT_NO_EMPTY), 'horizontal whitespace, no flag' => preg_split('~\h+~', $string), 'horizontal whitespace, flag' => preg_split('~\h+~', $string, -1, PREG_SPLIT_NO_EMPTY), ] );
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
array ( 'input' => ' A B C D ', 'space, no flag' => array ( 0 => ' A ', 1 => 'B', 2 => ' C', 3 => ' ', 4 => 'D', 5 => '', ), 'space, flag' => array ( 0 => ' A ', 1 => 'B', 2 => ' C', 3 => ' ', 4 => 'D', ), 'tab, no flag' => array ( 0 => '', 1 => 'A', 2 => ' B ', 3 => 'C ', 4 => ' D ', ), 'tab, flag' => array ( 0 => 'A', 1 => ' B ', 2 => 'C ', 3 => ' D ', ), 'whitespace, no flag' => array ( 0 => '', 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => '', ), 'whitespace, flag' => array ( 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', ), 'tab&space, no flag' => array ( 0 => '', 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => '', ), 'tab&space, flag' => array ( 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', ), 'horizontal whitespace, no flag' => array ( 0 => '', 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => '', ), 'horizontal whitespace, flag' => array ( 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', ), )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array ( 'input' => ' A B C D ', 'space, no flag' => array ( 0 => ' A ', 1 => 'B', 2 => ' C', 3 => ' ', 4 => 'D', 5 => '', ), 'space, flag' => array ( 0 => ' A ', 1 => 'B', 2 => ' C', 3 => ' ', 4 => 'D', ), 'tab, no flag' => array ( 0 => '', 1 => 'A', 2 => ' B ', 3 => 'C ', 4 => ' D ', ), 'tab, flag' => array ( 0 => 'A', 1 => ' B ', 2 => 'C ', 3 => ' D ', ), 'whitespace, no flag' => array ( 0 => '', 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => '', ), 'whitespace, flag' => array ( 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', ), 'tab&space, no flag' => array ( 0 => '', 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => '', ), 'tab&space, flag' => array ( 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', ), 'horizontal whitespace, no flag' => array ( 0 => '', 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => '', ), 'horizontal whitespace, flag' => array ( 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', ), )

preferences:
142.72 ms | 404 KiB | 157 Q