3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $utf8_str = "\xf0\x9f\x92\xa9"; $ret = ''; $length = mb_strlen($utf8_str, 'UTF-8'); for ($i = 0; $i < $length; $i++) { $char = mb_substr($utf8_str, $i, 1, 'UTF-8'); $l = strlen($char); if ($l <= 3) { $ret .= $char; } elseif ($l === 4) { $ret .= self::convert_char_to_cesu8($char); }// UTF-8で5文字以上になる文字はUnicodeとして不正なので無視(除去する) } $unko = $ret; var_dump($unko); $encode = json_encode($unko); var_dump($encode);
based on KhqTU
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Cannot access self:: when no class scope is active in /in/tRCEs:12 Stack trace: #0 {main} thrown in /in/tRCEs on line 12
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Fatal error: Cannot access self:: when no class scope is active in /in/tRCEs on line 12
Process exited with code 255.