/** * Replace emojis from text to img tag * * @param string $text Contains the complete message * @param string $show show smilies or remove it (for activities and notifications) */ public static function translateEmojis($text, $show = true) { $emojis = array('Ambivalent', 'Angry', 'Confused', 'Cool', 'Frown', 'Gasp', 'Grin', 'Heart', 'Hearteyes', 'Laughing', 'Naughty', 'Slant', 'Smile', 'Wink', 'Yuck'); return preg_replace_callback('@;(.*?);@', function ($hit) use(&$show, &$emojis) { if (in_array($hit[1], $emojis)) { if ($show) { return HHtml::image(Yii::app()->baseUrl . '/img/emoji/' . $hit[1] . '.png', $hit[1], array('data-emoji-name' => $hit[0], 'class' => 'atwho-emoji')); } return ''; } return $hit[0]; }, $text); }