Sevalla is the all-in-one PaaS for your web projects. Host and deploy your applications, databases, object storage, and static sites. Enjoy advanced deployment pipelines, a complete database studio, instant preview apps, and one-click templates. The pricing is simple: no hidden fees, no seat-based pricing, and you pay only for what you use. Get real human support from developers.

Get started now with a $50 credit at Sevalla.com.

Using emoji in PHP

Original – by Freek Van der Herten – 1 minute read

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.

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.