I am looking for the most efficient way to search for "Trigger words"
in a big string.

I have a string, $body which is all of the body of any particular
Usenet Post, so it can be as short as "Me too" and up to some, as yet
undecided, limit say around 10Kbytes.

I have a list of words in an array, maybe 50 words of up to 8
characters.

I need to search the $body for the presence of $word and if any $word
in the array is found in  $body Trigger an action.

This is a moderation bot for a beginners group, NO Flaming No swearing
No Abuse, you can imagine a list of words, idiot, fool, shit, FOAD, and
so on. When *any* one is found the post is diverted for manual
intervention, and searching stops.

Just guessing I would imagine 

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

{R}



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

Reply via email to