3v4l.org

run code in 300+ PHP versions simultaneously
<?php $output = "a b\tc"; $preg_match_matches = NULL; $preg_match_all_matches = NULL; $preg_replace_callback_array_count = NULL; var_dump([ 'preg_filter' => preg_filter('/[a-z]+/', 'X', $output, 0), 'preg_grep' => preg_grep('/^[a-z]+/', [$output, 'x'], 0), 'preg_match' => preg_match('/^[a-z]+/', $output, $preg_match_matches, 0, 0), 'preg_match $matches' => $preg_match_matches, 'preg_match_all' => preg_match_all('/^[a-z]+/', $output, $preg_match_all_matches, 0, 0), 'preg_match_all $matches' => $preg_match_all_matches, 'preg_replace' => preg_replace('/[a-z]+/', 'X', $output, 0), 'preg_replace_callback' => preg_replace_callback('/[a-z]+/', function($word) { return $word; }, $output, 0), 'preg_replace_callback_array' => preg_replace_callback_array([ '~[a]+~i' => function ($match) { return 'X'; }, '~[b]+~i' => function ($match) { return 'Y'; } ], $output, 0, $preg_replace_callback_array_count, 0), 'preg_split' => preg_split('/\s/', $output, 0, PREG_SPLIT_NO_EMPTY), ]); ?>
Output for 8.0.0, 8.1.0, 8.4.14
array(10) { ["preg_filter"]=> NULL ["preg_grep"]=> array(2) { [0]=> string(6) "a b c" [1]=> string(1) "x" } ["preg_match"]=> int(1) ["preg_match $matches"]=> array(1) { [0]=> string(1) "a" } ["preg_match_all"]=> int(1) ["preg_match_all $matches"]=> array(1) { [0]=> array(1) { [0]=> string(1) "a" } } ["preg_replace"]=> string(6) "a b c" ["preg_replace_callback"]=> string(6) "a b c" ["preg_replace_callback_array"]=> string(6) "a b c" ["preg_split"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } }

preferences:
208.45 ms | 1016 KiB | 32 Q