I am having a problem with comparing name strings. I have 3 variables
$fullname = 'MASNAD HOSSAIN NEHITH';
$firstName = 'Masnad';
$LastName = 'Nehith';
$fullname2 = 'MÄSNAD HOSSAIN NEHITH';
$firstName2 = 'Mäsnad';
$LastName2 = 'Nehith';
I thought of using strpos to see if the first name exists in the full name, but strpos is case sensitive.
I tried regular expressions using pregmatch but I am not sure how it works.
$pregmatch = preg_match("/$fullname/", $firstName);
if($pregmatch){
echo " it matches";
}
$pregmatch2 = preg_match("/$fullname2/", $firstName2);
if($pregmatch2){
echo " it matches";
}
You need to use mb_stripos instead of simple stripos for UTF-8 characters like as
if(mb_stripos('MÄSNAD HOSSAIN NEHITH', 'Mäsnad') !== false)
{
echo "UTF - 8 string".PHP_EOL;
}
if(mb_stripos('MASNAD HOSSAIN NEHITH', 'Masnad') !== false)
{
echo "Normal String";
}
Output
UTF - 8 string
Normal String
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With