敏感词过滤02------读取txt文件中的敏感词

版权声明:俗世凡人行(释) QQ:748507607 https://blog.csdn.net/weixin_41887155/article/details/88692807

敏感词库地址:

链接:https://pan.baidu.com/s/19pxbK4vjJpUFTuiDyFCuPA 
提取码:o7mn 

提取txt文件成一维数组

<?php
//敏感词数组位置
$fileUrl = "C:\Users\Administrator\Desktop/textfilter-master\keywords.txt"; 
$isss=file_exists($fileUrl) or exit("There is no file"); 
$file = fopen($fileUrl, "r"); 
$user=array();
$i=0;
//输出文本中所有的行,直到文件结束为止。
while(! feof($file))
{
    $user[$i]= fgets($file);//fgets()函数从文件指针中读取一行
    $i++;
}
fclose($file);
$user=array_filter($user);
//打印敏感词数组,如果要使用,就return $user;
print_r($user);

猜你喜欢

转载自blog.csdn.net/weixin_41887155/article/details/88692807
今日推荐