首页  >  文章  >  后端开发  >  PHP敏感字过滤代码

PHP敏感字过滤代码

WBOY
WBOY原创
2016-07-25 08:42:341089浏览
  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


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn