Add "mb_ucfirst"

master 1.1.0
Julien Rosset 3 years ago
parent 1d5d2eee7c
commit 7ea6da5541

@ -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}

@ -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}
*

@ -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')
);

Loading…
Cancel
Save