EmojiModule for Zend Framework 2
Master: , (*1)
Introduction
A sample emoji module for Zend Framework 2, (*2)
1.๐ Hello World
to :smile: Hello World, (*3)
2.๐ Hello World
to #1f601# Hello World
(You can save it to MySQL < 5.5), (*4)
3.#1f601# Hello World
to ๐ Hello World
, (*5)
4.๐ Hello World
to <span class="emoji emoji1f601"></span> Hello World
, (*6)
5.#1f601# Hello World
to <span class="emoji emoji1f601"></span> Hello World
, (*7)
Installation
With composer
-
Add this project in your composer.json:, (*8)
"require": {
"atans/emoji-module": "dev-master"
}
-
Running this command, (*9)
$ php composer.phar update
Post installation
```php
<?php
return array(
'modules' => array(
// ...
'EmojiModule',
),
);
```
How to use
-
Call emojimodule_emoji_service
in a controller, (*10)
public function indexAction() {
$emojiService = $this->getServiceLocator()->get('emojimodule_emoji_service');
$text = "\xF0\x9F\x98\x81 Hello World";
$variables = $emojiService->encode($text);
// Output: #1f601# Hello World (You can save it to MySQL now)
// Variables restore to unified
$unified = $emojiService->decode($variables);
// Output: \xF0\x9F\x98\x81 Hello World
// Variables to Html
$variablesToHtml = $emojiService->variablesToHtml($variables);
// Output: <span class="emoji emoji1f601"></span> Hello World
// Unified to html
$unifiedToHtml = $emojiService->unifiedToHtml($unified);
// Output: <span class="emoji emoji1f601"></span> Hello World
return array(
'unifiedToHtml' => $unifiedToHtml,
);
}
-
View, (*11)
copy https://raw.github.com/iamcal/php-emoji/master/emoji.css
and https://github.com/iamcal/php-emoji/blob/master/emoji.png
to '/public/css/', (*12)
headLink()->appendStylesheet($this->basePath() . '/public/css/emoji.css');
?>
-
View Helper, (*13)
emoji()->unifiedToHtml('๐ Hello World')
// Output: Hello World
?>