3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('display_errors', '1'); // display runtime errors error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED); // error reporting date_default_timezone_set('UTC'); function detect_encoding($ystr, $csetlist='UTF-8, ISO-8859-1, ISO-8859-15, ISO-8859-2, ISO-8859-9, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-16, UTF-7, ASCII, SJIS, EUC-JP, JIS, ISO-2022-JP, EUC-CN, GB18030, ISO-2022-KR, KOI8-R, KOI8-U') { // Fix: starting from PHP 7.1 it warns about illegal argument if using: ISO-8859-11 return mb_detect_encoding((string)$ystr, (string)$csetlist, true); // mixed: (bool) FALSE or (string) 'CHARSET' } $str = 'A + B'; echo detect_encoding($str); echo "\n"; echo mb_convert_encoding($str, 'UTF-8', detect_encoding($str)); echo "\n"; echo "\n"; $str = 'A - B'; echo detect_encoding('A - B'); echo "\n"; echo mb_convert_encoding($str, 'UTF-8', detect_encoding($str));
Output for 8.0.1 - 8.0.30, 8.1.18 - 8.1.28, 8.2.5 - 8.2.18, 8.3.0 - 8.3.6
UTF-8 A + B UTF-8 A - B
Output for 8.1.0 - 8.1.17, 8.2.0 - 8.2.4
UTF-7 A B UTF-8 A - B

preferences:
92.32 ms | 401 KiB | 89 Q