3v4l.org

run code in 300+ PHP versions simultaneously
<?php function unicodeToHtmlEntities($string) { $result = ''; $length = mb_strlen($string); for ($i = 0; $i < $length; $i++) { $result .= '&#' . chr(mb_substr($string, $i, 1)) . ';'; } return $result; } function unicodeToHtmlEntities2($string) { $result = ''; $length = strlen($string); for ($i = 0; $i < $length; $i++) { $result .= '&#' . chr(substr($string, $i, 1)) . ';'; } return $result; } echo unicodeToHtmlEntities('йцук');
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Uncaught TypeError: chr(): Argument #1 ($codepoint) must be of type int, string given in /in/CpfaV:8 Stack trace: #0 /in/CpfaV(8): chr('\xD0\xB9') #1 /in/CpfaV(22): unicodeToHtmlEntities('\xD0\xB9\xD1\x86\xD1\x83\xD0\xBA') #2 {main} thrown in /in/CpfaV on line 8
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: chr() expects parameter 1 to be int, string given in /in/CpfaV on line 8 Warning: chr() expects parameter 1 to be int, string given in /in/CpfaV on line 8 Warning: chr() expects parameter 1 to be int, string given in /in/CpfaV on line 8 Warning: chr() expects parameter 1 to be int, string given in /in/CpfaV on line 8 &#;&#;&#;&#;
Output for 5.6.0 - 5.6.38, 7.0.0 - 7.0.31, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
&#;&#;&#;&#;
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38
&#;&#;&#;&#;&#;&#;&#;&#;

preferences:
322.06 ms | 403 KiB | 451 Q