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
PHP String Handling
PHP explode() Function
PHP strpos() Function
PHP implode() Function
Exercises & Assignments
Write a PHP program to reverse the string
Write a PHP program to find the length of the string
Write a PHP program to count the words in the string
Write a PHP program to convert a string into uppercase
Interview Questions & Answers
How will you concatenate two strings in PHP?
What is the difference between single quote and double quote string in PHP?
Why we use PHP String functions trim(), ltrim() and rtrim()?
What PHP Function is used to find position of a string?
What is the use of ucwords() PHP String function?
What is the use of str_replace() PHP String function?
How to find String Length in PHP?