On Wed, 2006-05-17 at 16:38, Robin Vickery wrote:
> On 17/05/06, René Fournier <[EMAIL PROTECTED]> wrote:
> > Looking for suggestions on the most compute-efficient way to search
> > variable-length strings (~200 characters) for the occurrence of one
> > of about 100 possible needles. In other words:
>
> >
> >
> >
> > $needles = array ( 1 => "Hello Jim" , 2 => "Yellow Banana" , 3 =>
> > "Red Car", ... etc .... (100 elements)
> >
> > $haystack = "Once upon a time there was a programming language that
> > everyone loved. Its name was PHP, and the people that worked with it
> > also liked Yellow Bananas. One day...";
> >
>
> What version of php?
>
> If you're using php5 then you could do:
>
> <?php
> $count = 0;
> str_replace($needles, '', $haystack, $count);
> if ($count) { /* there was a match */ }
> ?>
Surely you meant strpos( $haystack, $needle ) ???
Incidentally do you need to match on words beginnings or endings? For
instance should 'put' match all of the following:
I put the apple core in the compost.
Someone always puts the fire out.
The car sputtered and died.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php