Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否从用户输入字符串中删除所有坏单词(脏话)?_Php_String - Fatal编程技术网

Php 是否从用户输入字符串中删除所有坏单词(脏话)?

Php 是否从用户输入字符串中删除所有坏单词(脏话)?,php,string,Php,String,我试图从字符串中取出脏话,并认为我已经完成了,直到有人在这个网站上告诉我: 那么,有没有办法让我检查一根绳子,直到它没有脏话为止 $a = array( 'duck', 'chit', 'dsshole' ); $str = 'duchitck-you-dssduckhole'; $newString = str_ireplace($a,'',$str); $newString = str_ireplace('-','',$newString); $newString = trim(

我试图从字符串中取出脏话,并认为我已经完成了,直到有人在这个网站上告诉我:

那么,有没有办法让我检查一根绳子,直到它没有脏话为止

$a = array( 'duck', 'chit', 'dsshole' ); 

$str = 'duchitck-you-dssduckhole'; 

$newString = str_ireplace($a,'',$str); 
$newString = str_ireplace('-','',$newString); 
$newString = trim($newString); 
echo $newString;  

使用中的contains函数,可以执行以下操作

$strFromSearchBox = 'duchitck you dssduckhole';
$theseWords = array('duck', 'chit', 'dsshole');

$newString = $strFromSearchBox;
while(contains($newString, $theseWords)) {
    $newString = str_replace($theseWords,'',$newString);
}

echo $newString;

使用中的contains函数,可以执行以下操作

$strFromSearchBox = 'duchitck you dssduckhole';
$theseWords = array('duck', 'chit', 'dsshole');

$newString = $strFromSearchBox;
while(contains($newString, $theseWords)) {
    $newString = str_replace($theseWords,'',$newString);
}

echo $newString;

简单的解决方案是传递第四个可选的$count参数

do { 
    $str = str_ireplace(..., ..., ..., $count);
} while ($count); 
但要真正消除咒语。。。。祝你好运。有太多的变体来完全过滤自然语言单词,werd,w0rd,w3rd,等等-如果有人想给某人起个名字,他们会找到一种方法;网站倾向于使用适度是有原因的


顺便说一句,这种方法是非常基本的,因为它没有实际单词的概念,只有字符串刺杀->插入。您可以使用正则表达式作为方便的单词边界,但在一天结束时,。

简单的解决方案是传递第四个可选的$count参数

do { 
    $str = str_ireplace(..., ..., ..., $count);
} while ($count); 
但要真正消除咒语。。。。祝你好运。有太多的变体来完全过滤自然语言单词,werd,w0rd,w3rd,等等-如果有人想给某人起个名字,他们会找到一种方法;网站倾向于使用适度是有原因的


顺便说一句,这种方法是非常基本的,因为它没有实际单词的概念,只有字符串刺杀->插入。您可以使用正则表达式作为方便的单词边界,但在一天结束时,.

一个用于从txt文件中筛选脏话的函数

PHP:

badwords.txt:

发誓,言语

结果:

Some s***r w***s to censor
用于从txt文件中筛选脏话的函数

PHP:

badwords.txt:

发誓,言语

结果:

Some s***r w***s to censor
如果可能的话,试着审查你的话。没有必要用脏话来理解问题/解决方案。我还建议在代码之外添加一些文本解释。这通常是一个更好的答案。如果可能的话,试着审查你的话。没有必要用脏话来理解问题/解决方案。我还建议在代码之外添加一些文本解释。这通常是一个更好的答案。不需要循环。str_replace将替换所有出现的单词。无需循环。str_replace将替换所有出现的单词。现在就这样。世界上有10个人将访问他们的网站,他们希望事情像高科技一样。。。不管怎样,现在就这样吧。世界上有10个人将访问他们的网站,他们希望事情像高科技一样。。。无论什么