首頁 >後端開發 >php教程 >PHP敏感字過濾程式碼

PHP敏感字過濾程式碼

WBOY
WBOY原創
2016-07-25 08:42:341161瀏覽
  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