Answer the question
In order to leave comments, you need to log in
Working with full name in php using switch or if else?
Another question:
Let's say I have a mailing list by email to all users on my site. When registering, they indicated only IFO. How to write code using switch or if else so that a letter with a body, let's say "Dear ....." came only to men, and "Dear ...." to women? Without fetching a field from the database.
In fact, I just need a script so that I can manually write Smirnova Ekaterina Sergeevna into the variable and the letter is sent with the body "Dear ...", and if Ivanov Konstantin Sergeevich then "Dear ..."
Answer the question
In order to leave comments, you need to log in
$a = 'Смирнова Екатерина Сергеевна';
$rest = substr($a, -2, 2);
switch ($rest) {
case 'ич':
$hello = 'Уважаемый '.$a;
break;
case 'на':
$hello = 'Уважаемая '.$a;
break;
default:
$hello = 'Уважаемый(-ая) '.$a;
break;
}
Cut out the last two letters from the end of the line, and:
if($last_str == 'ич') {
$text = 'Уважаемый ...';
} else
{
$text = 'Уважаемая ...';
}
https://dadata.ru/suggestions/#name
Can be used to determine gender by name.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question