PHP敏感字過濾代碼
$f = file('words.txt');
$words = array();
foreach ($f as $w) {
$words[] = preg_quote(trim($w), '/');
}
$text = file_get_contents('text.txt');
$start = microtime(true);
$reg = '/' . implode('|', $words) . '/S';
preg_match_all($reg, $text, $m);
$result = array();
$total = 0;
foreach ($m[0] as $w) {
if (!isset($result[$w])) {
$result[$w] = 1;
} else {
$result[$w]++;
}
$total++;
}
$end = microtime(true);
echo $end - $start, "\n";
echo $total, "\n";
print_r($result);</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!