WP_CLI
Inflector::ucwords()
Uppercases words with configurable delimeters between words.
Takes a string and capitalizes all of the words, like PHP's built-in ucwords function. This extends that behavior, however, by allowing the word delimeters to be configured, rather than only separating on whitespace.
Here is an example:
<?php $string = 'top-o-the-morning to all_of_you!'; echo \Doctrine\Common\Inflector\Inflector::ucwords($string); // Top-O-The-Morning To All_of_you! echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ '); // Top-O-The-Morning To All_Of_You! ?>
Method of the class: Inflector{}
No Hooks.
Return
String
. The string with all delimeter-separated words capitalized.
Usage
$result = Inflector::ucwords( $string, $delimiters );
- $string(string) (required)
- The string to operate on.
- $delimiters(string)
- A list of word separators.
Default: " \n\t\r\0\x0B-"
Inflector::ucwords() Inflector::ucwords code WP-CLI 2.8.0-alpha
public static function ucwords( $string, $delimiters = " \n\t\r\0\x0B-" ) { return preg_replace_callback( '/[^' . preg_quote( $delimiters, '/' ) . ']+/', function( $matches ) { return ucfirst( $matches[0] ); }, $string ); }