Constructing Initialisms and Acronyms
Learn how to construct initialisms and acronyms from a string of words.
We'll cover the following
An interesting thing we can do with the word helper methods is to create a new one to help construct initialisms or acronyms from a string of words. For example, we might want to shorten the name Jane Doe to JD or even J.D. We already have a way to retrieve a list of words from a string using wordSplit
. Our basic process will be to iterate each of the words of our string and extract the first character from each word and then concatenate them.
Leveraging our existing helper method and Laravel’s collections, this simple implementation could look like the example in the code below:
Get hands-on with 1200+ tech skills courses.