How do I get the abbreviation for a phrase in Laravel or php, for instance:
Technical Learning Curve in Front-end should give me TLCIFE
So far this is what I came up with:
function getAbbr($phrase) {
$words = explode(' ', $phrase);
$abbreviation = '';
foreach ($words as $word) {
$abbreviation .= strtoupper(substr($word, 0, 1));
}
return $abbreviation;
}
echo getAbbr("Technical Learning Curve in Front-end");
For now, it works but I was wondering if Laravel or PHP have any native functions or helpers that does it optimally.
New contributor
Jaleel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.