Re: Search for an exact string inside of another string
| From: | Rory McKinley | Date: | Mon, 13 Oct 2003 10:14:14 +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-165947@lists.php.net to get a copy of this message | ||
Hi
What you are looking for is a regular expression function, I would suggest
the following:
if(ereg($str1, $str2) == 1)
{
/*Found Bob in string*/
}
else
{
/*didn't find Bob
}
Rory McKinley
Nebula Solutions
+27 82 857 2391
rorym@nebula.co.za
"There are 10 kinds of people in this world,
those who understand binary and those who don't" (Unknown)
----- Original Message -----
From: "PHP Webmaster" <phpwadmin@phpwebmaster.co.uk>
To: <php-general@lists.php.net>
Sent: Sunday, October 12, 2003 2:11 AM
Subject: [PHP] Search for an exact string inside of another string
> 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.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>