Php function like fulltext mysql match

I want to check if two variables match each other using php. It could be a function such as php_match_function.
Take for example, I need business mail to be used in sign up

$email1=‘[email protected]’;
$email2=‘[email protected]’;
$business = ‘Tommy Business’;

function php_match_function()
{
}


if (php_match_function($business, $email1) ) 
{
    echo "Matched. Continue";
}
else
{
echo "Not Matched. Provide business email";
}

Well, you can use preg or other functions to match, but, this is more of a logical problem. First, the hospital name contains caps and spaces and may be spelled differently that the address in the email. You can check if the hospital name exists in the email with some tricky code, but, it may not work for all inputs.

Business names do not always match the incoming email. As you see in your example, the email1 is a gmail address and would not match the hospital name. If you want to just see if the hospital name is inside the text for the email1, you could do it something like this…

function php_match_function($email, $hospital) {
   //  Explain...  Remove spaces from hospital name, remove upper case, check if in email
   if( strpos(strtolower($email), strtolower(str_replace(" ", "", $hospital)))==0 ) {
      return false;
   } else {
      return true;
   }
}

This removes the spaces from hospital name, checks if that string is inside the email text and returns true or false as needed. Remember that functions use LOCAL data, so you can use the same names as outside the function and they are not altered. But, if the company name is “The Tommy Business” and the email1 is “[email protected]”, then it would be false. Hard to sort out this type of validation. But, hope this helps…

Thanks. I have made some changes. The function you provided is not working. Thanks

This will work for your example:

function php_match_function($business, $email)
{
    // "Clean" business name - remove spaces and make lower case
    $clean_business = strtolower(str_replace(' ', '', $business));

    // Make email lowercase to match against clean business name
    $clean_email = strtolower($email);

    return strpos($clean_email, $clean_business) !== false;
}

This may not work for all cases though; for example, would you want to match [email protected]? [email protected]?

Sponsor our Newsletter | Privacy Policy | Terms of Service