Difference between strstr() and stristr() in php

strstr() function

this function is used to find the first occurence of the string. this function is case-sensative. It has two parameters first parameter for the string and second parameter is used to define character which should be find from the string.


<?php
$email = 'john@tcs.com';
$email_data = strstr($email, 't');
echo $email_data;
?>
Output:- tcs.com

Try it Yourself

Suppose, the string has a duplicate character then find the first occurrence of the string.


<?php
$email = 'john_taylor@tcs.com';
$email_data = strstr($email, 't');
echo $email_data;
?>
Output:- taylor@tcs.com

Try it Yourself

Suppose, the string has a duplicate character then find the first occurrence of the string.

strstr() function is case-sensative


<?php
$email = 'john_Taylor@tcs.com';
$email_data = strstr($email, 't');
echo $email_data;
?>
Output:- tcs.com

Try it Yourself

stristr() function

this function works same as strstr() but it is a Case-insensitive manner.


<?php
$email = 'john_Taylor@tcs.com';
$email_data = stristr($email, 't');
echo $email_data;
?>
Output:- Taylor@tcs.com

Try it Yourself