Re: Fast search

From: Date: Wed, 17 May 2006 20:38:00 +0000
Subject: Re: Fast search
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-236362@lists.php.net to get a copy of this message
On 17/05/06, René Fournier <m5@renefournier.com> 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 */ } ?> -robin

« previous php.general (#236362) next »