Re: Search for an exact string inside of another string

From: Date: Sun, 12 Oct 2003 01:57:33 +0000
Subject: Re: Search for an exact string inside of another string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165871@lists.php.net to get a copy of this message
Try: if (strpos($str2, $str1) !== false) echo "$str1 is inside $str2"; else echo "could not find $str1 inside $str2"; "Php Webmaster" <phpwadmin@phpwebmaster.co.uk> wrote in message news:20031012001150.38275.qmail@pb1.pair.com... > Hi all, > > I have a little problem that I hope you can help me with. > > I have the following strings: > > $str1 = "Bob"; > $str2 = "My Name Is Bob"; > > How can I get PHP to look for $str1 inside of $str2? > > Also, what about if "Bob" inside of $str2 is in different places? > > I would like something like: > > if ($str1 IS INSIDE OF $str2) { > echo "str1 is inside of str2"; > } > else { > echo "could not find str1 inside of str2"; > } > > Any ideas appreciated.

« previous php.general (#165871) next »