Unicode::ucwords

public static Unicode::ucwords($text)

Capitalizes the first character of each word in a UTF-8 string.

Parameters

string $text: The text that will be converted.

Return value

string The input $text with each word capitalized.

Related topics

PHP wrapper functions
Functions that are wrappers or custom implementations of PHP functions.

File

core/lib/Drupal/Component/Utility/Unicode.php, line 377

Class

Unicode
Provides Unicode-related conversions and operations.

Namespace

Drupal\Component\Utility

Code

public static function ucwords($text) {
  $regex = '/(^|[' . static::PREG_CLASS_WORD_BOUNDARY . '])([^' . static::PREG_CLASS_WORD_BOUNDARY . '])/u';
  return preg_replace_callback($regex, function(array $matches) {
    return $matches[1] . Unicode::strtoupper($matches[2]);
  }, $text);
}
doc_Drupal
2016-10-29 09:50:25
Comments
Leave a Comment

Please login to continue.