3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'œ'; preg_match_all('/[^[:alnum:]]/', $str, $matches); echo "The string is read byte by byte, \nthe pattern matches the two bytes of œ separately.\n"; print_r($matches[0]); preg_match_all('/[^[:alnum:]]/u', $str, $matches); echo "\nThe string is read code point by code point encoded in utf-8,\nbut since [:alnum:] is extended,\nit contains œ, so there's no match.\n"; print_r($matches[0]); preg_match_all('/(*UCP)[^[:alnum:]]/', $str, $matches, PREG_OFFSET_CAPTURE); echo "\nThe string is read byte by byte,\nand because [:alnum:] contains œ with (*UCP),\nit fails at position 0 but succeeds on the second byte at position 1.\n"; print_r($matches[0]); preg_match_all('/(*UTF)[^[:alnum:]]/', $str, $matches); echo "\nThe string is read code point by code point,\n[:alnum:] doesn't contain œ,\nthe pattern matches at position 0 and return a code point.\n"; print_r($matches[0]);
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.4, 8.3.6 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
The string is read byte by byte, the pattern matches the two bytes of œ separately. Array ( [0] => � [1] => � ) The string is read code point by code point encoded in utf-8, but since [:alnum:] is extended, it contains œ, so there's no match. Array ( ) The string is read byte by byte, and because [:alnum:] contains œ with (*UCP), it fails at position 0 but succeeds on the second byte at position 1. Array ( [0] => Array ( [0] => � [1] => 1 ) ) The string is read code point by code point, [:alnum:] doesn't contain œ, the pattern matches at position 0 and return a code point. Array ( [0] => œ )
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 The string is read byte by byte, the pattern matches the two bytes of œ separately. Array ( [0] => � [1] => � ) The string is read code point by code point encoded in utf-8, but since [:alnum:] is extended, it contains œ, so there's no match. Array ( ) The string is read byte by byte, and because [:alnum:] contains œ with (*UCP), it fails at position 0 but succeeds on the second byte at position 1. Array ( [0] => Array ( [0] => � [1] => 1 ) ) The string is read code point by code point, [:alnum:] doesn't contain œ, the pattern matches at position 0 and return a code point. Array ( [0] => œ )

preferences:
44.27 ms | 1542 KiB | 4 Q