3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = array( 'ASCII' => 'ASCII', 'UTF-8' => "Tr\xc3\xb6t", 'Windows-1252 with ASCII' => "Tr\xf6t", 'Windows-1252 only' => "\xf6\xfd\x80", 'Windows-1252 only with an undefined character' => "\xf6\xfd\x81", ); $detect = array('ASCII', 'Windows-1252', 'UTF-8'); foreach ($strings as $name => $string) { $detected_loose = mb_detect_encoding($string, $detect, true); $detected_strict = mb_detect_encoding($string, $detect, false); if ($detected_loose === $detected_strict) { if ($detected_loose === false) { echo "'$name' could not be detected!\n"; } else { echo "'$name' was detected as $detected_loose\n"; } } else { echo "'$name' was " . ($detected_loose === false ? 'not detected' : "detected as $detected_loose") . ' in loose mode, but ' . ($detected_strict === false ? 'not detected' : "detected as $detected_strict") . " in strict mode\n"; } }
Output for 8.1.15 - 8.1.28, 8.2.1 - 8.2.18, 8.3.0 - 8.3.7
'ASCII' was detected as ASCII 'UTF-8' was detected as UTF-8 'Windows-1252 with ASCII' was detected as Windows-1252 'Windows-1252 only' was detected as Windows-1252 'Windows-1252 only with an undefined character' was detected as Windows-1252
Output for 8.1.0 - 8.1.14, 8.2.0
'ASCII' was detected as ASCII 'UTF-8' was detected as UTF-8 'Windows-1252 with ASCII' was detected as Windows-1252 'Windows-1252 only' was detected as Windows-1252 'Windows-1252 only with an undefined character' was not detected in loose mode, but detected as Windows-1252 in strict mode
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
'ASCII' was detected as ASCII 'UTF-8' was detected as UTF-8 'Windows-1252 with ASCII' could not be detected! 'Windows-1252 only' could not be detected! 'Windows-1252 only with an undefined character' could not be detected!
Output for 4.4.0 - 4.4.9, 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
'ASCII' was detected as ASCII 'UTF-8' was detected as UTF-8 'Windows-1252 with ASCII' was not detected in loose mode, but detected as UTF-8 in strict mode 'Windows-1252 only' was not detected in loose mode, but detected as UTF-8 in strict mode 'Windows-1252 only with an undefined character' was not detected in loose mode, but detected as UTF-8 in strict mode
Output for 4.3.11, 5.0.0 - 5.0.4
'ASCII' was detected as ASCII 'UTF-8' was detected as UTF-8 in loose mode, but detected as ASCII in strict mode 'Windows-1252 with ASCII' was not detected in loose mode, but detected as ASCII in strict mode 'Windows-1252 only' was detected as Windows-1252 in loose mode, but detected as UTF-8 in strict mode 'Windows-1252 only with an undefined character' was detected as Windows-1252 in loose mode, but detected as UTF-8 in strict mode
Output for 4.3.3 - 4.3.10
'ASCII' was detected as ASCII 'UTF-8' was detected as UTF-8 'Windows-1252 with ASCII' was not detected in loose mode, but detected as UTF-8 in strict mode 'Windows-1252 only' was detected as Windows-1252 in loose mode, but detected as UTF-8 in strict mode 'Windows-1252 only with an undefined character' was detected as Windows-1252 in loose mode, but detected as UTF-8 in strict mode
Output for 4.3.0 - 4.3.2
Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 14 Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 15 'ASCII' was detected as Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 14 Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 15 'UTF-8' was detected as Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 14 Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 15 'Windows-1252 with ASCII' was detected as Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 14 Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 15 'Windows-1252 only' was detected as Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 14 Warning: Wrong parameter count for mb_detect_encoding() in /in/8GaP0 on line 15 'Windows-1252 only with an undefined character' was detected as

preferences:
199.26 ms | 403 KiB | 314 Q