G
G
galsik2015-10-29 14:49:32
PHP
galsik, 2015-10-29 14:49:32

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

5 answer(s)
P
petyagrill, 2015-10-29
@galsik

$a = 'Смирнова Екатерина Сергеевна';
$rest = substr($a, -2, 2);
switch ($rest) {
  case 'ич':
    $hello = 'Уважаемый '.$a;
  break;
  case 'на':
    $hello = 'Уважаемая '.$a;
  break;	
  default:
    $hello = 'Уважаемый(-ая) '.$a;
  break;
}

A
Alexey Tsarapkin, 2015-10-29
@Dreamka

No way

E
eldar_web, 2015-10-29
@eldar_web

Cut out the last two letters from the end of the line, and:

if($last_str == 'ич') {
    $text = 'Уважаемый ...';
} else
{
    $text = 'Уважаемая ...';
}

This option is just not 100% perfect.

A
Alexander Aksentiev, 2015-10-29
@Sanasol

https://dadata.ru/suggestions/#name
Can be used to determine gender by name.

G
galsik, 2015-10-29
@galsik

I was not just familiar with the string processing functions, but now I understand everything. Thank you very much for your help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question