= 4? '' : $match[0];" statement Just remove the expression."/> = 4? '' : $match[0];" statement Just remove the expression.">

Home >Backend Development >PHP Problem >How to remove emoticons in php

How to remove emoticons in php

藏色散人
藏色散人Original
2020-09-03 11:01:383492browse

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.

How to remove emoticons in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn