<?php function persuade_name($name) { $persuade = ['ая' => 'е', 'бвгджзклмнпрстфхцчшщ' => '+у', 'й' => 'ю']; foreach ($persuade as $search => $replacement) { if ($last = mb_substr($name, -1) and mb_stripos($search, $last) !== false) { if (mb_strtoupper($last) === $last) { $replacement = mb_strtoupper($replacement); } if (substr($replacement, 0, 1) == '+') { $name .= substr_replace($replacement, '', 0, 1); } else { $name = preg_replace('/.$/u', $replacement, $name); } break; } } return $name; } echo persuade_name('Сергей'); // Сергею