Re: [PHP] string comparison on numerical array From: Brian Clark (brianj <email protected>)
Date: 11/10/00

Adrian Murphy wrote:

>I use the explode() function to split an article into words.so each element
>in the array is a word.how can i then do a string comparsion on this array
>to match a keyword provided in a search.
>i.e

<?php

function php3_in_array($string, $array)
{
    while(list($i,) = each($array))
    {
       if($array[$i] == $string) return true;
    }
}

?>

with PHP 3.x, or in_array() with PHP 4.x

http://www.php.net/manual/html/function.in-array.html

>$article[$i] = $keyword;

print in_array($keyword, $article) ? 'Yes' : 'No';

>so $keyword is provided and i need to get the value of $i.
>i'm doing this in order to display a snippet or snippets of text containing
>the keyword.
>thanx.

-Brian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>