toShort($str)
convert native unicode emoji to shortnames
Our recommendation is to unify all user inputted text by converting native unicode emoji, such as those inputted by mobile devices, to their corresponding shortnames. This demo shows you how to use the toShort($str) PHP function provided in our toolkit to do just that.
Feel free to enter native unicode emoji in the input below to test the conversion process. For a complete list of emoji and their shortnames check out emoji.codes.
Note: Once you start dealing with native unicode characters server side, it's important to ensure that your web stack is set up to handle UTF-8 character encoding. That is outside of the scope of our demos, but a quick Google Search will guide you in the right direction.
Input:
Output:
toShort($_POST['inputText']);
}
?>
PHP Snippet:
As of version 1.4.1 this library method has new syntax.
<?php
namespace Emojione;
// include the PHP library (if not autoloaded)
require('./../lib/php/autoload.php');
$client = new Client(new Ruleset());
if(isset($_POST['inputText'])) {
echo $client->toShort($_POST['inputText']);
}
?>
As of version 1.4.1 the following implementation has been deprecated. It's included in the library for backwards compatibility but will be removed at a later date.
<?php
// include the PHP library (if not autoloaded)
require('./../lib/php/autoload.php');
if(isset($_POST['inputText'])) {
echo Emojione\Emojione::toShort($_POST['inputText']);
}
?>