Skip to content

Instantly share code, notes, and snippets.

@guimadaleno
Created September 1, 2022 15:33
Show Gist options
  • Save guimadaleno/2cef203af2da02a092e5e41aede21e6a to your computer and use it in GitHub Desktop.
Save guimadaleno/2cef203af2da02a092e5e41aede21e6a to your computer and use it in GitHub Desktop.
Form acronyms from a string
<?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