PHP 屏蔽关键词
super
2024-10-05 20:20
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 条讨论