Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function full_name_to_short ($full_name, $format="A b. c."): array|string
{
$words = explode(" ", $full_name);
$format_keys = array("A", "B", "C");
$short_name = $format;
foreach ($format_keys as $index => $word) {
$short_name = str_replace($word, $words[$index], $short_name);
$short_name = str_replace(mb_strtolower($word), mb_substr($words[$index], 0, 1, 'UTF-8'), $short_name);
}
return $short_name;
}
echo full_name_to_short('Краснов Дмитрий Юрьевич');