3v4l.org

run code in 300+ PHP versions simultaneously
<?php function html_asciify(string $utf8String): string { $iterator = IntlBreakIterator::createCodePointInstance(); $iterator->setText($utf8String); $result = ''; foreach ($iterator as $pos) { if ($pos === 0) { continue; } $codePoint = $iterator->getLastCodePoint(); $result .= $codePoint <= 127 ? chr($codePoint) : '&#x' . dechex($codePoint) . ';'; } return $result; } $result = html_asciify("aaaååddd仕事bbbb\x80aaaa"); var_dump($result, html_entity_decode($result));
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
string(50) "aaa&#xe5;&#xe5;ddd&#x4ed5;&#x4e8b;bbbb&#xfffd;aaaa" string(27) "aaaååddd仕事bbbb�aaaa"
Output for 8.0.13
Fatal error: Uncaught Error: Class "IntlBreakIterator" not found in /in/mJXhQ:5 Stack trace: #0 /in/mJXhQ(25): html_asciify('aaa\xC3\xA5\xC3\xA5ddd\xE4\xBB\x95\xE4\xBA...') #1 {main} thrown in /in/mJXhQ on line 5
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33
Fatal error: Uncaught Error: Class 'IntlBreakIterator' not found in /in/mJXhQ:5 Stack trace: #0 /in/mJXhQ(25): html_asciify('aaa\xC3\xA5\xC3\xA5ddd\xE4\xBB\x95\xE4\xBA...') #1 {main} thrown in /in/mJXhQ on line 5
Process exited with code 255.

preferences:
130.39 ms | 409 KiB | 5 Q