stristr() is the case-insensitive form of strstr(). It returns the matching suffix of the string or false.
$text = 'Learn PHP Strings';
echo stristr($text, 'php'); // PHP StringsStart with this current pattern. The examples below are retained, corrected where necessary, and expanded for additional variations and output.
$haystack="myuserid@example.com";
$needle="@";
echo stristr($haystack,$needle,false);// @example.com
Output is
@example.com
Syntax
echo stristr($haystack,$needle,$before);
$haystack$needle$before$haystack="myuserid@example.com";
$needle="@";
echo stristr($haystack,$needle,true);// myuserid
Output is
myuserid
$haystack="Welcome to plus2net.com to learn PHP";
$needle="TO";
echo stristr($haystack,$needle);// to plus2net.com to learn PHP
Output is
to plus2net.com to learn PHP
$main_string="This is a test string <a href=https://www.plus2net.com>with a link</a> to plus2net";
if(stristr($main_string,"https://")){
echo "String contains a link or the text https:// inside it ";}
else {
echo "String does not contains a link or the text https:// inside it ";}
We can also use split command to get the domain part from email address.
$string='first second';
if (stristr($string,' ')) {
echo " There is blank space present inside the string ";
}else{
echo " There is NO blank space present inside the string ";
}
The output is
There is blank space present inside the string
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.