$word ) { $bare = mb_strtolower( (string) preg_replace( '/[^\p{L}\p{N}]/u', '', $word ) ); $small = in_array( $bare, self::SMALL, true ); $force = $boundary || $i === $last; if ( $small && ! $force && preg_match( '/^\p{Lu}\p{Ll}*$/u', $word ) ) { // An over-capitalized small word ("Of", "The") mid-title comes // back down. Only the plain Ucfirst form — "OF" in an acronym's // clothes is not ours to judge. $words[ $i ] = mb_strtolower( $word ); } elseif ( $force || ! $small ) { $words[ $i ] = self::cap( $word ); } $boundary = (bool) preg_match( '/[:\x{2014}\x{2013}-]$/u', $word ); } return implode( ' ', $words ); } /** * One word, first letter raised — unless the word's own spelling outranks us. * * @param string $word The word. * @return string */ private static function cap( $word ) { if ( preg_match( '/\p{Lu}/u', $word ) ) { return $word; // Its own capitals stand. } if ( preg_match( '/\p{L}\.\p{L}|^[@#]/u', $word ) ) { return $word; // A file, a domain, a handle. } return (string) preg_replace_callback( '/(?:^|-)\p{Ll}/u', static function ( $m ) { return mb_strtoupper( $m[0] ); }, $word ); } }