PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function full_name_to_short ($full_name, $format="A b."): string { $words = explode(" ", $full_name); $format_keys = array("A", "B"); $short_name = $format; $i = 0; foreach ($format_keys as $index => $word) { $short_name = str_replace($word, $words[$i], $short_name); $short_name = str_replace(mb_strtolower($word), mb_substr($words[$i], 0, 1, 'UTF-8'), $short_name); $i++; } return $short_name; } echo full_name_to_short('Краснов Дмитрий Юрьевич');
Show:  
Copy Clear