php method to remove emoticons: first define a "filterEmoji" method; then iterate through each character in the string; finally pass "strlen($match[0]) >= 4 ? '' : $ match[0];" statement can remove the expression.
Recommended: "PHP Video Tutorial"
php method to remove expressions:
Recently, users like to add emoji expressions to their nicknames when registering, which often causes database insertion queries to fail.
The temporary solution is to delete the emoji expression in the string. The code is as follows:
// 过滤掉emoji表情 function filterEmoji($str) { $str = preg_replace_callback( '/./u', function (array $match) { return strlen($match[0]) >= 4 ? '' : $match[0]; }, $str); return $str; }
The basic idea is to traverse each character in the string. If the length of the character is 4 characters section, delete it.
The above is the detailed content of How to remove emoticons in php. For more information, please follow other related articles on the PHP Chinese website!