Created
September 1, 2022 15:33
-
-
Save guimadaleno/2cef203af2da02a092e5e41aede21e6a to your computer and use it in GitHub Desktop.
Form acronyms from a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Form acronyms from a string | |
* @param string $str | |
*/ | |
function acronym ($str) | |
{ | |
$acr = ""; | |
$words = explode(" ", $str); | |
foreach ($words as $w) | |
if (!empty($w[0])) | |
$acr .= strtoupper($w[0]); | |
return $acr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment