3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ ')(8234@#$ABCFG3478&* hello', // mix '456456', // numeric 'ghijkl', // alphabetic '!@#$%^&*(', // non-alphanumeric ]; foreach ($strings as $string) { var_export( [ 'string' => $string, 'firstAlphaNumeric1' => preg_match('/[a-z0-9]/i', $string, $match) ? $match[0] : null, 'firstAlphaNumeric2' => $string[strcspn($string, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')] ?? null, 'firstAlphaNumeric3' => $string[strcspn($string, 'A..Zabcdefghijklmnopqrstuvwxyz0123456789')] ?? null, ] ); echo "\n"; }
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.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 'string' => ')(8234@#$ABCFG3478&* hello', 'firstAlphaNumeric1' => '8', 'firstAlphaNumeric2' => '8', 'firstAlphaNumeric3' => '8', ) array ( 'string' => '456456', 'firstAlphaNumeric1' => '4', 'firstAlphaNumeric2' => '4', 'firstAlphaNumeric3' => '4', ) array ( 'string' => 'ghijkl', 'firstAlphaNumeric1' => 'g', 'firstAlphaNumeric2' => 'g', 'firstAlphaNumeric3' => 'g', ) array ( 'string' => '!@#$%^&*(', 'firstAlphaNumeric1' => NULL, 'firstAlphaNumeric2' => NULL, 'firstAlphaNumeric3' => NULL, )

preferences:
103.32 ms | 1471 KiB | 4 Q