What is the difference between strstr() and stristr() in PHP?

Both functions find the first match of a text inside a string and return the part of the string from that match to the end. The difference is that strstr() is case-sensitive, and stristr() is case-insensitive (it ignores upper or lower case).

<?php
$email = "sonia@example.com";

echo strstr($email, "@") . "<br>";
echo strstr($email, "@", true) . "<br>";

var_dump(strstr("Hello World", "world"));
echo stristr("Hello World", "world");
?>

Output:

Tutorials Class - Output Window

@example.com
sonia
bool(false)
World

The third parameter true returns the part before the match. If there is no match, both functions return false. When you only want to know if a text exists, str_contains() is simpler.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.