strstr and stristr in PHP?

What is strstr and stristr in PHP?
Answer:
STRSTR:
Used to find the first occurrence of a string in a specified string, text block.

Example:
$email = 'someone@example.com';
$domain = strstr($email, '@');
echo $domain; //this will print @example.com
$user = strstr($email, '@', true); //
echo $user; // prints name

STRISTR:
Returns the matched substring. The stristr() function searches for the first occurrence of a string inside another string.
This function returns the rest of the string from the point where it matched, or FALSE, if the string to search for is not found.

Check the example below:
echo stristr("Hello world!",111);

THe output of the above will be o World!

Example:
$email = 'someone@example.com';
$domain = strstr($email, '@');
echo $domain; //this will print @example.com
$user = strstr($email, '@', true); //
echo $user; // prints name

0 comments:

Post a Comment