- json_decode: documentation ( source)
- strtok: documentation ( source)
- json_encode: documentation ( source)
<?php
function parse_emojis(string $string)
{
static $emojis;
if(!isset($emojis))
{
$emojis = [
'bbb' => json_decode(json_encode("\u{1F6A3}")),
];
}
$tok = strtok($string, ":");
while($tok !== false)
{
if(isset($emojis[$tok]))
{
yield $emojis[$tok];
}
else
{
yield $tok;
}
$tok = strtok(":");
}
}
foreach(parse_emojis('ok :bbb: bbl') as $part)
{
print "$part";
}