Function to check an email contains same character:
$str ="X@X.com";
$ret= chkbogus($str);
print_r($ret); //return There are 2 instance(s) of "x" in the string
$str ="Xxxxxxxxxxx@X.com";
$ret= chkbogus($str);
print_r($ret); //return There are 12 instance(s) of "x" in the string
function chkbogus($str)
{
$enter = 0;
$str = strtolower ($str);
$newStr = explode("@",$str);
$domainnm = explode(".",$newStr[1]);
$str = preg_replace('/\W/', '', $newStr[0].$domainnm[0]);
foreach (count_chars ($str, 1) as $i => $val)
{
if ($enter == 1)
{
$enter = 0;
continue;
}
if (chr ($i) == "\n")
{
// echo "There are $val instance(s) of \" Enter \" in the string.
";
$enter = 1;
}
elseif(strlen($str) == $val)
{
echo "There are $val instance(s) of \"" , chr ($i) , "\" in the string.
";
}
}
}
$str ="X@X.com";
$ret= chkbogus($str);
print_r($ret); //return There are 2 instance(s) of "x" in the string
$str ="Xxxxxxxxxxx@X.com";
$ret= chkbogus($str);
print_r($ret); //return There are 12 instance(s) of "x" in the string
function chkbogus($str)
{
$enter = 0;
$str = strtolower ($str);
$newStr = explode("@",$str);
$domainnm = explode(".",$newStr[1]);
$str = preg_replace('/\W/', '', $newStr[0].$domainnm[0]);
foreach (count_chars ($str, 1) as $i => $val)
{
if ($enter == 1)
{
$enter = 0;
continue;
}
if (chr ($i) == "\n")
{
// echo "There are $val instance(s) of \" Enter \" in the string.
";
$enter = 1;
}
elseif(strlen($str) == $val)
{
echo "There are $val instance(s) of \"" , chr ($i) , "\" in the string.
";
}
}
}
No comments:
Post a Comment