3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo mb_internal_encoding(), "\n\n\n"; /* premier test: on convertit en ISO-8859-1 pour produire des séquences UTF-8 invalides. Bien entendu, comme mb_internal_encoding est UTF-8, c'est dans cette encodage que mb_strlen va tenter de les lire. On remarque l'incohérence des résultats pour PHP < 8.3, résultats qui dépendent de la localisation du caractère  dans la chaîne. */ $test1 = [ 'mAm', 'mÂ', 'mÂm', 'mÂÂm' ]; echo "test 1:\n\n"; foreach ($test1 as $s) { printf( "%s:\n UTF-8: %d ISO-8859-1: %d\n", $s, mb_strlen($s), mb_strlen(mb_convert_encoding($s, 'ISO-8859-1', 'UTF-8')) ); } echo "\n\n\n"; /* ici on teste le caractère U+2030 ‰ e2 80 b0 PER MILLE SIGN, on interrompt sa séquence et on essaie différents cas de figure pour la suite */ $test2 = ["\xe2\x80\xb0", "\xe2\x80", "\xe2\x80L", "\xe2\x80\xe2\x80", "\xe2\x80LL"]; echo "test 2:\n\n"; foreach ($test2 as $s) { printf( "%s: UTF-8: %d\n", $s, mb_strlen($s) ); }
Output for 8.3.0 - 8.3.7
UTF-8 test 1: mAm: UTF-8: 3 ISO-8859-1: 3 mÂ: UTF-8: 2 ISO-8859-1: 2 mÂm: UTF-8: 3 ISO-8859-1: 3 mÂÂm: UTF-8: 4 ISO-8859-1: 4 test 2: ‰: UTF-8: 1 �: UTF-8: 1 �L: UTF-8: 2 ��: UTF-8: 2 �LL: UTF-8: 3
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
UTF-8 test 1: mAm: UTF-8: 3 ISO-8859-1: 3 mÂ: UTF-8: 2 ISO-8859-1: 2 mÂm: UTF-8: 3 ISO-8859-1: 2 mÂÂm: UTF-8: 4 ISO-8859-1: 3 test 2: ‰: UTF-8: 1 �: UTF-8: 1 �L: UTF-8: 1 ��: UTF-8: 2 �LL: UTF-8: 2

preferences:
76.78 ms | 402 KiB | 61 Q