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."): 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('Краснов Дмитрий Юрьевич');