php替换中文字符

$words = ["我", "你", "他", "她"];//过滤库
$sentence = "我和你一起去他家找她";//待过滤的句子
foreach($words as $word)//遍历过滤库的词
{
$len = strlen($word);//获取过滤词的长度
$pos = strpos($sentence,$word);//寻找过滤词的位置
$sentence = substr_replace($sentence,'', $pos, $len); 
}
echo $sentence;

 

posted @ 2019-10-27 16:18  岁月必然的流逝  阅读(1291)  评论(0)    收藏  举报