On Mon, 24 Feb 2003 22:35:35 +0100, Ernest E Vogelsinger wrote:

>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

Thank you very much that is brilliant, I would never have thought of
that. 

Do you think that:

if (preg_match($re, $posting, $hits)) would slow it down at all. The
$buzzwords will be kept in a file to be loaded before each run, every 5
minutes. I could therefore keep a count of which words hit most
frequently and move them to the top of the list.

{R}


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to