Using emoji in PHP
Using plain PHP it's kinda hard to display emoji characters.
In PHP 5 those characters could be generated by using json_encode
.
echo json_decode('"\uD83D\uDE00"'); //displays ?
I bet no one can type this code by heart. In PHP 7 it's a little bit easier. The hot new version of PHP allows unicode characters to be specified inside a string. This is what that looks like:
echo "\u{1F600}"; //displays ?
A little bit better than the PHP 5 version but still pretty hard to type.
For a project I needed to use some emoji characters. That's why I made a little PHP 7 package that makes working with emoji a lot easier. This is how you can use it:
echo Emoji::grinningFace(); //displays ?
All characters currently listed on unicode.org's list of emoji's are supported. Take a look at the emoji-package on GitHub to learn all the options.
EDIT: It turns out that emoji characters can be displayed in PHP 5 / PHP 7 just by... echo'ing them:
echo "?"; //displays ?
The package above may still be of use when your used IDE or font can't display emoji characters correctly in source code.
What are your thoughts on "Using emoji in PHP"?