Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing emojis from variable

Tags:

php

smarty

I'm using Smarty to pass in and display the contents of a first_name variable. Some users have Emoji characters (http://en.wikipedia.org/wiki/Emoji) in their first_name and I am wondering how I can either a) conditionally not display a user's first_name if it contains emojis or b) filter out emoji characters from first_name. Can this be done with Smarty? Can it be done with PHP in Smarty?

like image 677
conbask Avatar asked Oct 30 '12 22:10

conbask


1 Answers

The emoji are encoded in the block U+1F300–U+1F5FF.

preg_replace('/\xEE[\x80-\xBF][\x80-\xBF]|\xEF[\x81-\x83][\x80-\xBF]/', '', $first_name)

this will strip those out

like image 75
omercnet Avatar answered Oct 03 '22 20:10

omercnet