I have a small bit of code that I'm using to output the initials of a group of names:
$names = array("Tom Hanks", "Julia Roberts");
$initials = implode('/', array_map(function ($name) {
preg_match_all('/w/', $name, $matches);
return implode('', $matches[0]);
}, $names));
echo $initials ;
This outputs TH/JR
. But what I would prefer is THank/JRobe
where the first 4 letters of the last name are used.
What is the best way to achieve that?