By enxox on
For anyone who needs it
this code is able to clean emoji elements from, for example, the instagram title in a feed.
function removeEmoji($text) {
$clean_text = "";
// Match Emoticons
$regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
$clean_text = preg_replace($regexEmoticons, '', $text);
// Match Miscellaneous Symbols and Pictographs
$regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
$clean_text = preg_replace($regexSymbols, '', $clean_text);
// Match Transport And Map Symbols
$regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
$clean_text = preg_replace($regexTransport, '', $clean_text);
// Match flags (iOS)
$regexTransport = '/[\x{1F1E0}-\x{1F1FF}]/u';
$clean_text = preg_replace($regexTransport, '', $clean_text);
return $clean_text;
}
I've tested it modifying aggregator.parser.inc to strip emoji code from instagram title, because I can't upgrade my database from utf8 to utf8mb4 and emoji code breaks my run cron.
Comments
Yo
very helpful thanks. saved me some time !!!
fresh
I'm thinking of using this with
Emoji for PHP
This way we can allow emoticons from various devices :)
Using your code to detect emoticons and only then, send it thru the php function:
emoji_docomo_to_unified($text);
I think I'll load this php file with
module_load_include
Thanks!
thanks, this was really helpful! I went ahead and made this more concise:
Worked to an extent
To make your code even more concise(if you don't mind missing the comments)
But this code only worked to an extent for me. To remove all emoji's I ended up adding on to this code to include the removal of more emoji's and account for unicode variation selectors. Haven't done very extensive testing with it so it is probably far from perfect and may not be very efficient yet, but from the few small tests that I have done it appears to remove every emoji that IOS 7 has to offer.
Thanks. Your improved
Thanks. Your improved regular expression did the trick for me. The original wasn't getting this icon: http://www.iemoji.com/view/emoji/12/smileys/face-with-stuck-out-tongue-a...
Hi!
Hi!
I am new in Drupal. How to implement this code in drupal 7?
Spot on
Thanks for sharing lajical - Exactly what I needed!
Removing Characters by another way
Hello,
Thanks for posting the code here which helps me in my project.
When I used above code with TCPDF library and trying to generate PDF, code replaces the emoji characters with question mark "?".
I found another code given below, removes emoji characters and question mark "?" as well :
Thanks alot Ravi, your
Thanks alot Ravi, your suggestion really helped us :)