3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ 'A number at the end 1357', '2368 Letters and spaces 8675309', ]; foreach ($strings as $string) { var_export([ 'strcspn' => strcspn($string, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '), //reduces to 'a..zA..Z ' 'strspn' => strspn($string, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '), //reduces to 'a..zA..Z ' 'strpbrk' => strpbrk($string, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '), //reduces to 'a..zA..Z ' 'strtok' => strtok($string, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '), //reduces to 'a..zA..Z ' 'strtok2' => strtok('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '), //reduces to 'a..zA..Z ' ]); echo "\n--\n"; }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 'strcspn' => 0, 'strspn' => 20, 'strpbrk' => 'A number at the end 1357', 'strtok' => '1357', 'strtok2' => false, ) -- array ( 'strcspn' => 4, 'strspn' => 0, 'strpbrk' => ' Letters and spaces 8675309', 'strtok' => '2368', 'strtok2' => '8675309', ) --

preferences:
105.66 ms | 407 KiB | 5 Q