rfc:mb_ucfirst

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:mb_ucfirst [2024/01/18 08:40] – Change Under Discussion youkidearitairfc:mb_ucfirst [2024/03/20 21:13] (current) – Implemented mb_ucfirst and mb_lcfirst youkidearitai
Line 1: Line 1:
 ====== PHP RFC: Multibyte for ucfirst, lcfirst functions, mb_ucfirst mb_lcfirst ====== ====== PHP RFC: Multibyte for ucfirst, lcfirst functions, mb_ucfirst mb_lcfirst ======
-  * Version: 0.1+  * Version: 0.1.2
   * Date: 2024-01-16   * Date: 2024-01-16
   * Author: Author: Yuya Hamada(https://github.com/youkidearitai), youkidearitai@gmail.com   * Author: Author: Yuya Hamada(https://github.com/youkidearitai), youkidearitai@gmail.com
-  * Status: Under Discussion+  * Status: Implemented
   * First Published at: http://wiki.php.net/rfc/mb_ucfirst   * First Published at: http://wiki.php.net/rfc/mb_ucfirst
  
Line 12: Line 12:
 function mb_ucfirst(string $str, ?string $encoding = null): string function mb_ucfirst(string $str, ?string $encoding = null): string
 { {
-    return mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, null, $encoding);+    return mb_convert_case(mb_substr($str, 0, 1, $encoding), MB_CASE_TITLE, $encoding) . mb_substr($str, 1, null, $encoding);
 } }
 </code> </code>
Line 32: Line 32:
 function mb_ucfirst(string $string, ?string $encoding = null): string function mb_ucfirst(string $string, ?string $encoding = null): string
 </code> </code>
 +
 +The first character in mb_ucfirst uses Unicode title case.
  
 <code> <code>
Line 37: Line 39:
 </code> </code>
  
-According to research about Unicode, some (natural) lanugage doesn'may expected behavior, please deal with it in userland if any wrongBecause (naturallanguages is a lot of existsit is difficult to deal in mbstring.+From what I've researched with Unicode, it may not behave as expected in some languages. In that case, please deal with it in userland. 
 + 
 +For example, In Vietnamese, the first letter is not always capitalized. 
 +  
 +  * ngày Quốc khánh 2-9 (September 2nd National Day) 
 +  * tiếng Nhật (Japanese) 
 + 
 +Another exampleIn Georgian should uses title case. 
 + 
 +  * mb_strtoupper("აბგ") (ani bani gani, U+10D0 U+10D1 U+10D2) -> ᲐᲑᲒ(U+1C90 U+1C91 U+1C92) 
 +  * mb_strtoupper("lj")(U+01C9) -> "LJ" (U+01C7) 
 + 
 +Correct case. 
 + 
 +  * mb_ucfirst("აბგ") -> "აბგ" (U+10D0 U+10D1 U+10D2) 
 +  * mb_ucfirst("lj") -> "Lj" (U+01C9 -> U+01C8)
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 69: Line 86:
 ===== Voting ===== ===== Voting =====
  
 +<doodle title="Add mb_ucfirst and mb_lcfirst functions" auth="youkidearitai" voteType="single" closed="true" closeon="2024-03-07T00:00:00Z">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Implementation ===== ===== Implementation =====
rfc/mb_ucfirst.1705567229.txt.gz · Last modified: 2024/01/18 08:40 by youkidearitai