RE: [PHP] array search
| From: | Philip Olson | Date: | Fri, 31 Aug 2001 21:31:25 +0000 |
| Subject: | RE: [PHP] array search | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65556@lists.php.net to get a copy of this message | ||
btw, you may want to search for a name surrounded by spaces as philip vs
philips, jim vs jimmy, etc. probably other considerations as well, or
maybe not :)
philip
On Fri, 31 Aug 2001, Philip Olson wrote:
> try this :
>
> $people = array ('philip','sasheen','jim');
> $string = 'Hi, my name is philip, I miss Sasheen';
>
> foreach ($people as $person) {
>
> if (stristr($string,$person)) {
> $matches[] = $person;
> }
> }
>
> // results live in $matches now.
>
> print_r($matches);
>
> stristr is case insensitive, strstr is case sensitive. modify to suit
> your needs.
>
> regards,
> Philip Olson
>
>
> On Fri, 31 Aug 2001, Joseph Bannon wrote:
>
> > What about going the other way? Say I have a sentence...
> >
> > "Hi, my name is Bob."
> >
> > ...and I want to search the sentence for one of the values (people) in the
> > array...
> >
> > $people = array("Jim","John","JP","Bob");
> >
> > Can this be done?
> >
> >
> > Thanks,
> > Joseph
> >
> >
> >
> >
> > -----Original Message-----
> >
> > yes, in_array($person, $people)!
> >
> > however, you may take a look into the manual.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>