当前位置:Gxlcms > PHP教程 > PHP敏感字过滤代码

PHP敏感字过滤代码

时间:2021-07-01 10:21:17 帮助过:13人阅读

  1. $f = file('words.txt');
  2. $words = array();
  3. foreach ($f as $w) {
  4. $words[] = preg_quote(trim($w), '/');
  5. }
  6. $text = file_get_contents('text.txt');
  7. $start = microtime(true);
  8. $reg = '/' . implode('|', $words) . '/S';
  9. preg_match_all($reg, $text, $m);
  10. $result = array();
  11. $total = 0;
  12. foreach ($m[0] as $w) {
  13. if (!isset($result[$w])) {
  14. $result[$w] = 1;
  15. } else {
  16. $result[$w]++;
  17. }
  18. $total++;
  19. }
  20. $end = microtime(true);
  21. echo $end - $start, "\n";
  22. echo $total, "\n";
  23. print_r($result);

PHP

人气教程排行