How to remove emoticons in php

藏色散人
Release: 2023-03-05 17:32:01
Original
3351 people have browsed it

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;
 }
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!