PHP Emoji Render

4 years ago

iksaku

Code

$zwj = "\u{200D}";

// Reference, may come from 'foreach' loop
$short_code = ':family_man_woman_girl_boy:';
$url = 'https://github.githubassets.com/images/icons/emoji/unicode/1f468-1f469-1f467-1f466.png?v8';

if (preg_match('/^((?!unicode).)*$/', $url)) {
    // Custom Github emoji
    return;
}

preg_match('/(?<=\/)[a-zA-Z0-9\-]+(?=\.png)/', $url, $matches);

$parts = array_map(
  fn (string $part) => mb_chr(hexdec($part)),
  explode('-', $matches[0])
);

$unicode = implode($zwj, $parts);

echo $unicode;

Output

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ
HELO: Local email testing for your desktop!