早睡早起,方能养生
Sleep early rise early, way to keep healthy

PHP 屏蔽关键词

super
2024-10-05 20:20
views 315

// 敏感词替换
    public function sensitiveWord($content, $replace_sign = '*')
    {
        $keywords = [
            '草',
            '日',
            'cnm'
            
        ];
        if (empty($keywords)) {
            return $content;
        }
        foreach ($keywords as $k => $v) {
            $len = mb_strlen($v);
            $find = strpos($content, $v);
            if ($find === false)
                continue;
            $replace_str = '';
            for($i = 0; $i < $len; $i++) {
                $replace_str .= $replace_sign;
            }
            $content = str_replace($v, $replace_str, $content);
        }
        return $content;
    }


分享
0 条讨论
top