Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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攻击textarea_Php_Javascript_Html - Fatal编程技术网

比较;“单词数组”;用php攻击textarea

比较;“单词数组”;用php攻击textarea,php,javascript,html,Php,Javascript,Html,我昨天问了这个问题: 现在我想用php做同样的事情 有没有简单的代码 谢谢 更新:我想根据数组测试textarea输入,如果找到匹配的坏单词,die() 谢谢 这将用“******”替换坏词 编辑: 要检查字符串中是否存在来自坏单词的任何单词,请执行以下操作: foreach( $bad_words as $bad ){ if( stristr($posted, $bad) !== FALSE ) { $contains_bad_words = TRUE; } } 您可以尝试

我昨天问了这个问题:

现在我想用php做同样的事情

有没有简单的代码

谢谢

更新:我想根据数组测试textarea输入,如果找到匹配的坏单词,die()

谢谢

这将用“******”替换坏词

编辑:

要检查字符串中是否存在来自坏单词的任何单词,请执行以下操作:

foreach( $bad_words as $bad ){
 if( stristr($posted, $bad) !== FALSE )
 {
  $contains_bad_words = TRUE;
 }    
}

您可以尝试以下方法:

$bad_words = array('ring','sarah','chuck');

$intersect = array_intersect(explode(' ', strtolower($_POST['textarea'])), $bad_words);

if(count($intersect)) die('You should wash your mouth out with soap!');

数组_intersect将比较两个不同的字数组,并返回两个数组中存在的所有值。因此,如果count($intersect)不是0(在本例中计算为false),则可以存在脚本并输出错误。

执行与javascript问题中建议的完全相同的操作。学会理解原则,而不仅仅是抄袭。如果你能发布完整的问题,而不仅仅是发布一个链接,那将更有帮助。另外,您是想过滤掉“坏”字,还是想测试是否有坏字,然后让它通过验证?如果验证失败,你需要告诉他们哪些单词没有通过吗?好的,对不起,诺亚,我想测试一下是否有任何不好的单词。。。然后失败或php中的“die()”。请更新问题的主体。虽然我很感谢您的回复,但如果每个人都能直接看到对您问题的编辑,而不必通过评论进行搜索,那就更有帮助了。事实上,我正在寻找一个if语句,如果发现不好的词,我将取消整个操作。非常感谢,还有,有没有办法让这个案例变得不敏感?我的意思是,当数组中只有“Bad”时,如果“Bad”“Bad”“Bad”就进行匹配。。。
$bad_words = array('ring','sarah','chuck');

$intersect = array_intersect(explode(' ', strtolower($_POST['textarea'])), $bad_words);

if(count($intersect)) die('You should wash your mouth out with soap!');