PHP remove Emojis or 4 byte characters

Emojis or BMP character have more than three bytes and maximum of four bytes per character. To store this type of characters, UTF8mb4 character set is needed in MySQL.
And it is available only in MySQL 5.5.3 and above versions.

Otherwise, remove all 4 byte characters and store it in DB. Example script follows,
#to remove 4byte characters like emojis etc..
function replace_4byte($string) {
    return preg_replace('%(?:
          \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
        | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
        | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
    )%xs', '', $string);    
}
 
PHP UTF8mb4 Emojis Posted on 2016-06-14 06:55:19