3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('codepoint_encode')) { function codepoint_encode($str) { return substr(json_encode($str), 1, -1); } } if (!function_exists('codepoint_decode')) { function codepoint_decode($str) { return json_decode(sprintf('"%s"', $str)); } } if (!function_exists('mb_internal_encoding')) { function mb_internal_encoding($encoding = NULL) { return ($from_encoding === NULL) ? iconv_get_encoding() : iconv_set_encoding($encoding); } } if (!function_exists('mb_convert_encoding')) { function mb_convert_encoding($str, $to_encoding, $from_encoding = NULL) { return iconv(($from_encoding === NULL) ? mb_internal_encoding() : $from_encoding, $to_encoding, $str); } } if (!function_exists('mb_chr')) { function mb_chr($ord, $encoding = 'UTF-8') { if ($encoding === 'UCS-4BE') { return pack("N", $ord); } else { return mb_convert_encoding(mb_chr($ord, 'UCS-4BE'), $encoding, 'UCS-4BE'); } } } if (!function_exists('mb_ord')) { function mb_ord($char, $encoding = 'UTF-8') { if ($encoding === 'UCS-4BE') { list(, $ord) = (strlen($char) === 4) ? @unpack('N', $char) : @unpack('n', $char); return $ord; } else { return mb_ord(mb_convert_encoding($char, 'UCS-4BE', $encoding), 'UCS-4BE'); } } } if (!function_exists('mb_htmlentities')) { function mb_htmlentities($string, $hex = true, $encoding = 'UTF-8') { return preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', function ($match) use ($hex) { return sprintf($hex ? '&#x%X;' : '&#%d;', mb_ord($match[0])); }, $string); } } if (!function_exists('mb_html_entity_decode')) { function mb_html_entity_decode($string, $flags = null, $encoding = 'UTF-8') { return html_entity_decode($string, ($flags === NULL) ? ENT_COMPAT | ENT_HTML401 : $flags, $encoding); } } const EMOJIS = [ "00a9" => [["\u00A9\uFE0F", "\u00A9"], "\uE24E", "\uDBBA\uDF29", ["copyright"], 0, 0, 11, 0], "00ae" => [["\u00AE\uFE0F", "\u00AE"], "\uE24F", "\uDBBA\uDF2D", ["registered"], 0, 1, 11, 0], "203c" => [["\u203C\uFE0F", "\u203C"], "", "\uDBBA\uDF06", ["bangbang"], 0, 2, 15, 0] ]; function parse_emojis(string $string): string { preg_match_all('/(?<match>:.*:)/', $string, $matches, PREG_PATTERN_ORDER); $emojis = $matches['match']; foreach ($emojis as $emoji): $emoji_name = trim($emoji, ':'); foreach (EMOJIS as $key => $value): $names = $value[3]; foreach($names as $name): if ($name == $emoji_name): $string = str_replace($emoji, mb_chr('0x' . $key), $string); break; endif; endforeach; endforeach; endforeach; return $string; } var_dump(parse_emojis(' Ok. Nice :registered: Very very very nice :bangbang: Good. '));
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.4, 8.3.6
Fatal error: Uncaught TypeError: mb_chr(): Argument #1 ($codepoint) must be of type int, string given in /in/hcGBU:84 Stack trace: #0 /in/hcGBU(84): mb_chr('0x00ae') #1 /in/hcGBU(99): parse_emojis('\n\t\tOk.\n\n\t\tNice ...') #2 {main} thrown in /in/hcGBU on line 84
Process exited with code 255.
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 Fatal error: Uncaught TypeError: mb_chr(): Argument #1 ($codepoint) must be of type int, string given in /in/hcGBU:84 Stack trace: #0 /in/hcGBU(84): mb_chr('0x00ae') #1 /in/hcGBU(99): parse_emojis('\n\t\tOk.\n\n\t\tNice ...') #2 {main} thrown in /in/hcGBU on line 84
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: A non well formed numeric value encountered in /in/hcGBU on line 84 Notice: A non well formed numeric value encountered in /in/hcGBU on line 84 string(52) " Ok. Nice Very very very nice Good. "
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.3.32 - 7.3.33
string(52) " Ok. Nice Very very very nice Good. "
Output for 7.2.0 - 7.2.33
Notice: A non well formed numeric value encountered in /in/hcGBU on line 84 Notice: A non well formed numeric value encountered in /in/hcGBU on line 84 string(50) " Ok. Nice Very very very nice Good. "
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected ':', expecting '{' in /in/hcGBU on line 71
Process exited with code 255.

preferences:
250.07 ms | 401 KiB | 296 Q