Re: String searching peformance

From: Date: Mon, 24 Feb 2003 21:35:35 +0000
Subject: Re: String searching peformance
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-136981@lists.php.net to get a copy of this message
At 21:22 24.02.2003, {R}ichard Ashton spoke out and said: --------------------[snip]-------------------- >while ( $flag == true ) >if (strpos($body, $word[]) > 0) {$flag=false} > >What I really need to know is which is the fastest loop? >Which is the fastest match, strpos? >Which is the fastest comparison? >What other optimisations are possible to maximise search speed? > >I would expect to keep a frequency hit count and sort the $words[] so >that the most frequent hits are found first, remembering that only >$body with NO $words in then are automatically posted, so every word >must be tested. > >I don't know sufficient internals to pick the fastest method. I will be >running with 4.3.1 on FreeBSD 4.6 --------------------[snip]-------------------- I'd suggest something like this: $buzzwords = array('idiot', 'fool', 'shit', 'FOAD'); $re = '/(' . implode('|',$buzzwords).')/is'; if (preg_match($re, $posting)) // bad word found else // cleared You only need to make sure that your buzzwords dont contain a '/' - you could change the regex delimiter then, or simply escape it in the array. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#136981) next »