├── README.md ├── LICENSE └── Emoji.php /README.md: -------------------------------------------------------------------------------- 1 | php-emoji 2 | ========= 3 | 4 | Simple PHP libiary to convert Emoji(iOS 6,7,8,OS X) to unicode 5 | 6 | ------- 7 | iOS 9 Support : @desexy 8 | 9 | >usage 10 | 11 | ``` php 12 | 21 | ``` 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 萌萌工作室(MoemoeStudio) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Emoji.php: -------------------------------------------------------------------------------- 1 | gzsgcs@gmail.com. All Rights Reserved 5 | * 6 | **************************************************************************/ 7 | /** 8 | * @file Emoji.php 9 | * @author Yin(gzsgcs@gmail.com) 10 | * @date 2014/12/09 3:27:02 11 | * @remark 截止iOS 8,共有845个Emoji表情(there are 845 emojis in iOS 8 and OS X) 12 | **/ 13 | 14 | class Emoji 15 | { 16 | /** 17 | * Encode emoji in text 18 | * @param string $text text to encode 19 | */ 20 | public static function Encode($text) { 21 | return self::convertEmoji($text,"ENCODE"); 22 | } 23 | 24 | /** 25 | * Decode emoji in text 26 | * @param string $text text to decode 27 | */ 28 | public static function Decode($text) { 29 | return self::convertEmoji($text,"DECODE"); 30 | } 31 | 32 | private static function convertEmoji($text,$op) { 33 | if($op=="ENCODE"){ 34 | return preg_replace_callback('/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{1F000}-\x{1FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F9FF}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F9FF}][\x{1F000}-\x{1FEFF}]?/u',array('self',"encodeEmoji"),$text); 35 | }else{ 36 | return preg_replace_callback('/(\\\u[0-9a-f]{4})+/',array('self',"decodeEmoji"),$text); 37 | } 38 | } 39 | 40 | private static function encodeEmoji($match) { 41 | return str_replace(array('[',']','"'),'',json_encode($match)); 42 | } 43 | 44 | private static function decodeEmoji($text) { 45 | if(!$text) return ''; 46 | $text = $text[0]; 47 | $decode = json_decode($text,true); 48 | if($decode) return $decode; 49 | $text = '["' . $text . '"]'; 50 | $decode = json_decode($text); 51 | if(count($decode) == 1){ 52 | return $decode[0]; 53 | } 54 | return $text; 55 | } 56 | } 57 | ?> 58 | --------------------------------------------------------------------------------