3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function mb_detect_encoding2 ($string, $enc=null, $ret=null) { static $enclist = array( 'UTF-8', 'ASCII', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', 'Windows-1251', 'Windows-1252', 'Windows-1254', ); $result = false; foreach ($enclist as $item) { $sample = iconv($item, $item, $string); if (md5($sample) == md5($string)) { if ($ret === NULL) { $result = $item; } else { $result = $item; } break; } } return $result; } $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_encoding2($string, $detect, true); $detected_strict = mb_detect_encoding2($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 5.5.0 - 5.5.34, 5.6.0 - 5.6.20, 5.6.28 - 7.0.5, 7.0.14 - 7.1.0
'ASCII' was detected as UTF-8 'UTF-8' was detected as UTF-8 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 'Windows-1252 with ASCII' was detected as ISO-8859-1 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 'Windows-1252 only' was detected as ISO-8859-1 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 Notice: iconv(): Detected an illegal character in input string in /in/nFT5m on line 16 'Windows-1252 only with an undefined character' was detected as ISO-8859-1
Output for 7.0.6
Fatal error: Uncaught Error: Call to undefined function iconv() in /in/nFT5m:16 Stack trace: #0 /in/nFT5m(36): mb_detect_encoding2('ASCII', Array, true) #1 {main} thrown in /in/nFT5m on line 16
Process exited with code 255.
Output for 5.5.35, 5.6.21
Fatal error: Call to undefined function iconv() in /in/nFT5m on line 16
Process exited with code 255.
Output for 5.0.0 - 5.4.45
'ASCII' was detected as UTF-8 'UTF-8' was detected as UTF-8 'Windows-1252 with ASCII' was detected as ISO-8859-1 'Windows-1252 only' was detected as ISO-8859-1 'Windows-1252 only with an undefined character' was detected as ISO-8859-1
Output for 4.4.5 - 4.4.9
<br /> <b>Fatal error</b>: Call to undefined function: iconv() in <b>/in/nFT5m</b> on line <b>16</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.4.4
<br /> <b>Fatal error</b>: Call to undefined function: iconv() in <b>/in/nFT5m</b> on line <b>16</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1
<br /> <b>Fatal error</b>: Call to undefined function: iconv() in <b>/in/nFT5m</b> on line <b>16</b><br />