Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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_Arrays_Mysqli - Fatal编程技术网

php坏字内容过滤器

php坏字内容过滤器,php,arrays,mysqli,Php,Arrays,Mysqli,我有一个可以工作的内容过滤器,它不能像我希望的那样工作。 例如,如果我说“badword you i badword hate you”,整个内容输出为“[CONTENT DELETED]”,但我希望它说“******you i*********hate you” 代码中几乎没有bug。请检查以下工作示例: <?php $str = "Kiss my badwordhere"; echo filter($str) . "\n"; $str = "badwordhere anywhereb

我有一个可以工作的内容过滤器,它不能像我希望的那样工作。 例如,如果我说“badword you i badword hate you”,整个内容输出为“[CONTENT DELETED]”,但我希望它说“******you i*********hate you”


代码中几乎没有bug。请检查以下工作示例:

<?php
$str = "Kiss my badwordhere";
echo filter($str) . "\n";

$str = "badwordhere anywherebadword";
echo filter($str) . "\n";


function filter($string) {
  $words = array("badwordhere", "anywherebadword");
  $new =   array("****", "*******");
  $string1 = str_ireplace($words, $new, $string);
  $left = preg_replace("/[\* ]+/", "", $string1);
  if (strlen($left) == 0) {
    $string1 = "[ Content Deleted ]";
    return $string1;
  }
  else {
    return $string1;
  }
}
?>

代码中几乎没有bug。请检查以下工作示例:

<?php
$str = "Kiss my badwordhere";
echo filter($str) . "\n";

$str = "badwordhere anywherebadword";
echo filter($str) . "\n";


function filter($string) {
  $words = array("badwordhere", "anywherebadword");
  $new =   array("****", "*******");
  $string1 = str_ireplace($words, $new, $string);
  $left = preg_replace("/[\* ]+/", "", $string1);
  if (strlen($left) == 0) {
    $string1 = "[ Content Deleted ]";
    return $string1;
  }
  else {
    return $string1;
  }
}
?>

这是一项不可能完成的任务,你可以用一本很长的字典找出不好的单词,但你不能找出这些单词的所有变体:
FuUuCk
b1owJ0b
。。。简言之,试图这样做只是浪费时间,并不能取代主持人。新闻:我们现在是2017年,你可以毫无风险地停止使用所有的
mysql\uuuu
函数。我知道我不能全部停止它们,这不是我的问题……也许,但这是我的答案。这是一项不可能的任务,你可以抓住不好的单词(用很长的字典),但你不能抓住这些单词的所有变体:
FuUuCk
b1owJ0b
。。。简言之,试图这样做只是浪费时间,并不能取代主持人。新闻:我们现在是2017年,你可以毫无风险地停止使用所有的
mysql\uu
函数。我知道我不能全部停止它们,这不是我的问题……也许,但这是我的答案。
Kiss my ****
[ Content Deleted ]