★ wanayoo — archive 1999 http://fr.php.net/manual/en/function.strstr.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousstrspnstrtoknext
Last updated: Mon, 19 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

strstr

(PHP 3, PHP 4 )

strstr -- Find first occurrence of a string

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
add a note about notes
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.)

add a note about notes
previousstrspnstrtoknext
Last updated: Mon, 19 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Wed Aug 21 04:21:22 2002 CEST