diff --git a/boostrap.php b/boostrap.php index 56b3003..f774d7a 100644 --- a/boostrap.php +++ b/boostrap.php @@ -2,6 +2,18 @@ use jrosset\MbstringExtended; +if (!function_exists('mb_ucfirst')) { + /** + * Multi-bytes implementation for {@see https://www.php.net/manual/function.ucfirst.php ucfirst} + * + * @param string $string The input string + * + * @return string The resulting string + */ + function mb_ucfirst (string $string): string { + return MbstringExtended::ucfirst($string); + } +} if (!function_exists('mb_str_pad')) { /** * Multi-bytes implementation for {@see https://www.php.net/manual/function.str-pad.php str_pad} diff --git a/src/MbstringExtended.php b/src/MbstringExtended.php index c660660..9334225 100644 --- a/src/MbstringExtended.php +++ b/src/MbstringExtended.php @@ -6,6 +6,16 @@ namespace jrosset; * Class for โ€œmissingโ€ mbstring functions */ final class MbstringExtended { + /** + * Multi-bytes implementation for {@see https://www.php.net/manual/function.ucfirst.php ucfirst} + * + * @param string $string The input string + * + * @return string The resulting string + */ + public static function ucfirst (string $string): string { + return mb_strtoupper(mb_substr($string, 0, 1)) . mb_strtolower(mb_substr($string, 1)); + } /** * Multi-bytes implementation for {@see https://www.php.net/manual/function.str-pad.php str_pad} * diff --git a/tests/test.php b/tests/test.php index d6a96eb..442f7fc 100644 --- a/tests/test.php +++ b/tests/test.php @@ -2,4 +2,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; -echo mb_str_pad('๐„ž', 20, '=', STR_PAD_RIGHT, 'UTF-8'); +var_dump( + mb_ucfirst('TEST AVEC Plusieurs mOts'), + mb_str_pad('๐„ž', 20, '=', STR_PAD_RIGHT, 'UTF-8') +);