3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $examples = array( 'Valid ASCII' => array("a", true), 'Valid 2 Octet Sequence' => array("\xc3\xb1", true), 'Invalid 2 Octet Sequence' => array("\xc3\x28", false), 'Invalid Sequence Identifier' => array("\xa0\xa1", false), 'Valid 3 Octet Sequence' => array("\xe2\x82\xa1", true), 'Invalid 3 Octet Sequence (in 2nd Octet)' => array("\xe2\x28\xa1", false), 'Invalid 3 Octet Sequence (in 3rd Octet)' => array("\xe2\x82\x28", false), 'Valid 4 Octet Sequence' => array("\xf0\x90\x8c\xbc", true), 'Invalid 4 Octet Sequence (in 2nd Octet)' => array("\xf0\x28\x8c\xbc", false), 'Invalid 4 Octet Sequence (in 3rd Octet)' => array("\xf0\x90\x28\xbc", false), 'Invalid 4 Octet Sequence (in 4th Octet)' => array("\xf0\x28\x8c\x28", false), 'Valid 5 Octet Sequence (but not Unicode!)' => array("\xf8\xa1\xa1\xa1\xa1", false), 'Valid 6 Octet Sequence (but not Unicode!)' => array("\xfc\xa1\xa1\xa1\xa1\xa1", false), ); function checkWithPreg($str) { return preg_match('//u', $str); } function checkWithMbstring($str) { return mb_check_encoding($str, 'UTF-8'); } function test($actual, $expected, $title) { echo $actual == $expected ? "[Success]" : "[Fail]"; echo " $title\n"; } function runTests($method) { global $examples; foreach($examples as $title => $arr) { list($str, $bool) = $arr; test($method($str), $bool, $title); } } runTests('checkWithPreg'); echo "\n"; runTests('checkWithMbstring');
Output for 5.4.0 - 7.1.0
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Success] Valid 5 Octet Sequence (but not Unicode!) [Success] Valid 6 Octet Sequence (but not Unicode!) [Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Success] Valid 5 Octet Sequence (but not Unicode!) [Success] Valid 6 Octet Sequence (but not Unicode!)
Output for 4.4.9, 5.2.5 - 5.3.29
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Success] Valid 5 Octet Sequence (but not Unicode!) [Success] Valid 6 Octet Sequence (but not Unicode!) [Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!)
Output for 4.4.5 - 4.4.8, 5.2.1 - 5.2.4
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!) [Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!)
Output for 4.4.3 - 4.4.4, 5.1.3 - 5.2.0
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!) [Success] Valid ASCII [Success] Valid 2 Octet Sequence [Fail] Invalid 2 Octet Sequence [Fail] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Fail] Invalid 3 Octet Sequence (in 2nd Octet) [Fail] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Fail] Invalid 4 Octet Sequence (in 2nd Octet) [Fail] Invalid 4 Octet Sequence (in 3rd Octet) [Fail] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!)
Output for 5.0.0 - 5.1.2
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!) Fatal error: Call to undefined function mb_check_encoding() in /in/kdNpr on line 21
Process exited with code 255.
Output for 4.3.5 - 4.4.2
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Success] Invalid 2 Octet Sequence [Success] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Success] Invalid 3 Octet Sequence (in 2nd Octet) [Success] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Success] Invalid 4 Octet Sequence (in 2nd Octet) [Success] Invalid 4 Octet Sequence (in 3rd Octet) [Success] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!) Fatal error: Call to undefined function: mb_check_encoding() in /in/kdNpr on line 21
Process exited with code 255.
Output for 4.3.2 - 4.3.4
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Fail] Invalid 2 Octet Sequence [Fail] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Fail] Invalid 3 Octet Sequence (in 2nd Octet) [Fail] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Fail] Invalid 4 Octet Sequence (in 2nd Octet) [Fail] Invalid 4 Octet Sequence (in 3rd Octet) [Fail] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!) Fatal error: Call to undefined function: mb_check_encoding() in /in/kdNpr on line 21
Process exited with code 255.
Output for 4.3.0 - 4.3.1
[Success] Valid ASCII [Success] Valid 2 Octet Sequence [Fail] Invalid 2 Octet Sequence [Fail] Invalid Sequence Identifier [Success] Valid 3 Octet Sequence [Fail] Invalid 3 Octet Sequence (in 2nd Octet) [Fail] Invalid 3 Octet Sequence (in 3rd Octet) [Success] Valid 4 Octet Sequence [Fail] Invalid 4 Octet Sequence (in 2nd Octet) [Fail] Invalid 4 Octet Sequence (in 3rd Octet) [Fail] Invalid 4 Octet Sequence (in 4th Octet) [Fail] Valid 5 Octet Sequence (but not Unicode!) [Fail] Valid 6 Octet Sequence (but not Unicode!) Fatal error: Call to undefined function: mb_check_encoding() in /in/kdNpr on line 21