|
48 | 48 | * - mb_strstr - Finds first occurrence of a string within another
|
49 | 49 | * - mb_strwidth - Return width of string
|
50 | 50 | * - mb_substr_count - Count the number of substring occurrences
|
| 51 | + * - mb_ucfirst - Make a string's first character uppercase |
| 52 | + * - mb_lcfirst - Make a string's first character lowercase |
51 | 53 | *
|
52 | 54 | * Not implemented:
|
53 | 55 | * - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
|
@@ -871,6 +873,51 @@ public static function mb_str_pad(string $string, int $length, string $pad_strin
|
871 | 873 | }
|
872 | 874 | }
|
873 | 875 |
|
| 876 | + public static function mb_ucfirst(string $string, ?string $encoding = null): string |
| 877 | + { |
| 878 | + if (null === $encoding) { |
| 879 | + $encoding = self::mb_internal_encoding(); |
| 880 | + } |
| 881 | + |
| 882 | + try { |
| 883 | + $validEncoding = @self::mb_check_encoding('', $encoding); |
| 884 | + } catch (\ValueError $e) { |
| 885 | + throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
| 886 | + } |
| 887 | + |
| 888 | + // BC for PHP 7.3 and lower |
| 889 | + if (!$validEncoding) { |
| 890 | + throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
| 891 | + } |
| 892 | + |
| 893 | + $firstChar = mb_substr($string, 0, 1, $encoding); |
| 894 | + $firstChar = mb_convert_case($firstChar, MB_CASE_TITLE, $encoding); |
| 895 | + |
| 896 | + return $firstChar . mb_substr($string, 1, null, $encoding); |
| 897 | + } |
| 898 | + |
| 899 | + public static function mb_lcfirst(string $string, ?string $encoding = null): string |
| 900 | + { |
| 901 | + if (null === $encoding) { |
| 902 | + $encoding = self::mb_internal_encoding(); |
| 903 | + } |
| 904 | + |
| 905 | + try { |
| 906 | + $validEncoding = @self::mb_check_encoding('', $encoding); |
| 907 | + } catch (\ValueError $e) { |
| 908 | + throw new \ValueError(sprintf('mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
| 909 | + } |
| 910 | + |
| 911 | + // BC for PHP 7.3 and lower |
| 912 | + if (!$validEncoding) { |
| 913 | + throw new \ValueError(sprintf('mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
| 914 | + } |
| 915 | + $firstChar = mb_substr($string, 0, 1, $encoding); |
| 916 | + $firstChar = mb_convert_case($firstChar, MB_CASE_LOWER, $encoding); |
| 917 | + |
| 918 | + return $firstChar . mb_substr($string, 1, null, $encoding); |
| 919 | + } |
| 920 | + |
874 | 921 | private static function getSubpart($pos, $part, $haystack, $encoding)
|
875 | 922 | {
|
876 | 923 | if (false === $pos) {
|
|
0 commit comments