Home How To Check Whether a Character Exists in a String PHP?

How To Check Whether a Character Exists in a String PHP?

102 viewsPHP
1

We have a string of email ID with abuhozaifa8@gmail.com  and we want to check @ exist in a string with PHP, so will use simple strchr() function of PHP and will check @ or any other character exists in the string.

You can learn more about strchr() from w3school.com

How To Check Whether a Character Exists in a String PHP?

<?php
error_reporting(0);
$string = "abuhozaifa8@gmail.com";
if(strchr($string, '@')) {
    echo '@ Exist in String';
}
else {
    echo "Doesn't Exist";
}

Output

@ Exist in String
Changed status to publish