Skip to content

Instantly share code, notes, and snippets.

@4RSIM3R
Created February 20, 2024 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4RSIM3R/cf6c10007c8af8abebc70c0a0724aff7 to your computer and use it in GitHub Desktop.
Save 4RSIM3R/cf6c10007c8af8abebc70c0a0724aff7 to your computer and use it in GitHub Desktop.
Generate Company Alias
function shortenName(string $name): string
{
$words = explode(' ', $name);
$shortened = '';
foreach ($words as $word) {
// Take the first letter of each word and concatenate
$shortened .= strtoupper(substr($word, 0, 1));
}
return $shortened;
}
echo shortenName("Kereta Api Indonesia"); // KAI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment