3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toAscii($s) { static $transliterator = NULL; if ($transliterator === NULL && class_exists('Transliterator', FALSE)) { $transliterator = \Transliterator::create('Any-Latin; Latin-ASCII'); } $s = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s); $s = strtr($s, '`\'"^~?', "\x01\x02\x03\x04\x05\x06"); $s = str_replace( ["\xE2\x80\x9E", "\xE2\x80\x9C", "\xE2\x80\x9D", "\xE2\x80\x9A", "\xE2\x80\x98", "\xE2\x80\x99", "\xC2\xB0"], ["\x03", "\x03", "\x03", "\x02", "\x02", "\x02", "\x04"], $s ); if ($transliterator !== NULL) { $s = $transliterator->transliterate($s); } if (ICONV_IMPL === 'glibc') { $s = str_replace( ["\xC2\xBB", "\xC2\xAB", "\xE2\x80\xA6", "\xE2\x84\xA2", "\xC2\xA9", "\xC2\xAE"], ['>>', '<<', '...', 'TM', '(c)', '(R)'], $s ); $s = iconv('UTF-8', 'WINDOWS-1250//TRANSLIT//IGNORE', $s); $s = strtr($s, "\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e" . "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3" . "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8" . "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe" . "\x96\xa0\x8b\x97\x9b\xa6\xad\xb7", 'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.'); $s = preg_replace('#[^\x00-\x7F]++#', '', $s); } else { $s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s); } $s = str_replace(['`', "'", '"', '^', '~', '?'], '', $s); return strtr($s, "\x01\x02\x03\x04\x05\x06", '`\'"^~?'); } echo toAscii('ášěíáčšíěá');
Output for 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: iconv(): Wrong encoding, conversion from "UTF-8" to "WINDOWS-1250//TRANSLIT//IGNORE" is not allowed in /in/QJ7Jk on line 22
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: iconv(): Wrong encoding, conversion from "UTF-8" to "WINDOWS-1250//TRANSLIT//IGNORE" is not allowed in /in/QJ7Jk on line 22
Output for 8.0.13
Fatal error: Uncaught Error: Undefined constant "ICONV_IMPL" in /in/QJ7Jk:17 Stack trace: #0 /in/QJ7Jk(36): toAscii('\xC3\xA1\xC5\xA1\xC4\x9B\xC3\xAD\xC3\xA1\xC4\x8D\xC5\xA1\xC3...') #1 {main} thrown in /in/QJ7Jk on line 17
Process exited with code 255.
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12
aseiacsiea
Output for 7.3.32 - 7.3.33, 7.4.33
Warning: Use of undefined constant ICONV_IMPL - assumed 'ICONV_IMPL' (this will throw an Error in a future version of PHP) in /in/QJ7Jk on line 17 Fatal error: Uncaught Error: Call to undefined function iconv() in /in/QJ7Jk:31 Stack trace: #0 /in/QJ7Jk(36): toAscii('\xC3\xA1\xC5\xA1\xC4\x9B\xC3\xAD\xC3\xA1\xC4\x8D\xC5\xA1\xC3...') #1 {main} thrown in /in/QJ7Jk on line 31
Process exited with code 255.
Output for 7.4.26 - 7.4.32
Notice: iconv(): Wrong charset, conversion from `UTF-8' to `WINDOWS-1250//TRANSLIT//IGNORE' is not allowed in /in/QJ7Jk on line 22

preferences:
197.71 ms | 401 KiB | 296 Q