Re: Fast search

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17/05/06, René Fournier <m5@xxxxxxxxxxxxxxxx> 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

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux