Description
string
strstr ( string haystack, string needle)
Returns part of haystack string from the
first occurrence of needle to the end of
haystack.
If needle is not found, returns FALSE.
If needle is not a string, it is converted
to an integer and applied as the ordinal value of a character.
Note:
This function is case-sensitive. For case-insensitive searches, use
stristr().
Example 1. strstr() example $email = 'user@example.com';
$domain = strstr($email, '@');
print $domain; // prints @example.com |
|
See also ereg(), preg_match(),
strchr(), stristr(),
strpos(), strrchr(), and
substr().
User Contributed Notes strstr |
 |
wls@wwco.com
01-Oct-2000 05:07 |
|
If you're looking for the index of where the string starts, see strpos()
|
|
arni@linux.is
23-Nov-2000 04:00 |
|
This functions is also widely used for checking if a string is in a string
since it returns false if the string was not found in
container.
$string = "PHP";
$container = "I
love writing PHP code.";
if(strstr($container,$string))
{
echo "found it.";
} else {
echo "not
found.";
}
|
|
corky6921@NOSPAMPLEASE-yahoo.com
14-Sep-2001 01:19 |
|
This function can be very useful. For instance:
I had to test for
Windows because I was setting a file to download to the client computer
from a UNIX server, and the carriage returns are different. Here is a tiny
little statement that works (tested on Win/IE, Win/Netscape, Solaris/IE and
Solaris/Netscape.)
if(strstr(getenv('HTTP_USER_AGENT'), 'Win')) {
$os = "Windows";
}
else {
$os = "Not
Windows";
};
More like this @ the get_browser function
page (including how to test for IE vs. Netscape, etc.)
|
|
 |