1. 程式人生 > >php 去除常見中文停用詞(過濾敏感詞)

php 去除常見中文停用詞(過濾敏感詞)

在用sphinx通過文章標題匹配相關文章時,去除停用詞後調出的文章相關性更好。

<?php
header("Content-type:text/html;charset=utf-8"); 
$str = file_get_contents('stop.txt');//將常見中文停用詞表內容讀入到一個字串中
$badword = explode("\r\n", $str);//轉換成陣列//print_r($arr);
$badword1 =array_combine($badword,array_fill(0,count($badword),'*')); //過濾敏感詞時替換成*
$bb = '確定安裝的PowerShell版本https://www.itread01.com/';
$str = strtr($bb,$badword1); echo $str; ?>