3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php 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, sprintf('\\u{%s}', $key), $string); break; endif; endforeach; endforeach; endforeach; return $string; } var_dump(parse_emojis(' Ok. Nice :registered: Very very very nice :bangbang: Good. '));
based on d5nbB
Output for hhvm-3.21.3 - 3.22.0, 7.0.0 - 7.2.6
string(66) " Ok. Nice \u{00ae} Very very very nice \u{203c} Good. "
Output for hhvm-3.18.5
Warning: Constants may only evaluate to scalar values in /in/X8CEJ on line 7 Notice: Use of undefined constant EMOJIS - assumed 'EMOJIS' in /in/X8CEJ on line 17 Warning: Invalid argument supplied for foreach() in /in/X8CEJ on line 27 Notice: Use of undefined constant EMOJIS - assumed 'EMOJIS' in /in/X8CEJ on line 17 Warning: Invalid argument supplied for foreach() in /in/X8CEJ on line 27 string(72) " Ok. Nice :registered: Very very very nice :bangbang: Good. "
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/X8CEJ on line 9
Process exited with code 255.