public static function NameUnicodeExtras::initials in Name Field 8
Generate the initials of all first characters in a string.
Note that this is case-insensitive, camel case words are treated as a single word.
Parameters
string $text: The text that will be converted.
string $delimitor: An optional string to separate each character.
Return value
string The input $text with first letters of each word capitalized.
2 calls to NameUnicodeExtras::initials()
- NameFormatParser::renderComponent in src/
NameFormatParser.php - Renders a name component value.
- NameUnicodeExtrasTest::testNameUnicodeExtras in tests/
src/ Unit/ NameUnicodeExtrasTest.php - Test NameUnicodeExtras functions.
File
- src/
NameUnicodeExtras.php, line 43
Class
- NameUnicodeExtras
- Provides custom Unicode-related extension methods.
Namespace
Drupal\nameCode
public static function initials($text, $delimitor = '') {
$text = mb_strtolower($text);
$results = [];
foreach (array_filter(self::explode($text)) as $word) {
$results[] = mb_substr($word, 0, 1);
}
$text = implode($delimitor, $results);
$text = mb_strtoupper($text);
return $text ? $text . $delimitor : '';
}