Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Last active July 3, 2017 21:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wilcorrea/82428509c25f88cf166b026042158f2e to your computer and use it in GitHub Desktop.
Save wilcorrea/82428509c25f88cf166b026042158f2e to your computer and use it in GitHub Desktop.
<?php
/**
* @param string $string
* @param array $avoid (['de', 'da', 'a', 'e', 'o'])
* @return string
*/
function initials(string $string, array $avoid = null): string
{
$words = preg_split("/\s+/", $string);
$restrict = $avoid ? $avoid : ['de', 'da', 'a', 'e', 'o'];
$input = array_diff($words, $restrict);
$function = function ($item) {
return ((string)$item){0};
};
return implode('', array_map($function, $input))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment