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;
?>
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;
?>
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;
?>
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;
?>
Difference between strstr() and stristr() in php – Objective Questions (MCQs)
Q1. Which function performs a case-insensitive search?
Q2. Which function is case-sensitive?
Q3. What do both strstr() and stristr() return?
Q4. If no match is found, what do both functions return?
Q5. Which function should be used to find a word regardless of case?