Home  >  Article  >  Backend Development  >  留言板内容不文明词语过滤的有关问题

留言板内容不文明词语过滤的有关问题

WBOY
WBOYOriginal
2016-06-13 11:59:121187browse

留言板内容不文明词语过滤的问题
如题。

现在不文明词语是个数组,在留言板内容后,我需要用这个不文明词语数组里面逐个查找留言板内容中是否有匹配的。如果有则提示。在纠结着怎么样才能实现这个不文明词语过滤的效果
------解决方案--------------------
12行的 if($srs = false){
改为 if($srs == false){
------解决方案--------------------
if($srs === false){
                echo "error 第" . $i . "次
";
            }else{
                echo "您输入的内容包含不文明用语'$fw[$i]',请重新输入";
                break;
            }

//楼主该好好看手册了。
------解决方案--------------------
之前写了个php替换敏感字符的类,有白名单和黑名单。
黑名单的会替换为*。

可以参考一下:http://blog.csdn.net/fdipzone/article/details/8486985
------解决方案--------------------
你读文件时没有去掉换行符

$fn = "common/filterword.txt";<br />$fd = fopen($fn, "rb");<br />if(file_exists($fn)){<br />   $fw = array();<br />   while(!feof($fd)){<br />     $fw[] = trim(fgets($fd));<br />   }<br />}<br />print_r($fw);<br />

干脆这样
$fn = "common/filterword.txt";<br />$fw = file($fn, FILE_IGNORE_NEW_LINES <br><font color='#FF8000'>------解决方案--------------------</font><br> FILE_SKIP_EMPTY_LINES);<br />print_r($fw);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn