Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Unicode.php

function Unicode::ucwords

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.
2 calls to Unicode::ucwords()
HandlerBase::caseTransform in core/modules/views/src/Plugin/views/HandlerBase.php
Transform a string by a certain method.
IconExtractorSettingsForm::getOptions in core/lib/Drupal/Core/Theme/Icon/IconExtractorSettingsForm.php
Get option list for enumerations.

File

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

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] . mb_strtoupper($matches[2]);
    }, $text);
}
RSS feed
Powered by Drupal