rfc:mb_trim

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_trim [2023/10/18 07:03] – Add my GitHub youkidearitairfc:mb_trim [2024/04/15 08:40] (current) – old revision restored (2023/11/24 06:26) youkidearitai
Line 3: Line 3:
   * Date: 2023-10-18   * Date: 2023-10-18
   * Author: Yuya Hamada (https://github.com/youkidearitai), youkidearitai@gmail.com based on 8ctopus(https://github.com/8ctopus), hello@octopuslabs.io   * Author: Yuya Hamada (https://github.com/youkidearitai), youkidearitai@gmail.com based on 8ctopus(https://github.com/8ctopus), hello@octopuslabs.io
-  * Status: Draft+  * Status: Implemented
   * First Published at: http://wiki.php.net/rfc/mb_trim   * First Published at: http://wiki.php.net/rfc/mb_trim
  
 ===== Introduction ===== ===== Introduction =====
 PHP does not have a multibyte equivalent of the trim function. It is possible to get close enough behavior using preg_replace("/^\s+|\s+$/u", '', $string), however adding a pre-built function to do this will improve the readability and clarity of PHP code. It will also standardize how it is done as it can be tricky. This feature would be of use to many PHP developers with varying levels of experience and would complete the mbstring extension. PHP does not have a multibyte equivalent of the trim function. It is possible to get close enough behavior using preg_replace("/^\s+|\s+$/u", '', $string), however adding a pre-built function to do this will improve the readability and clarity of PHP code. It will also standardize how it is done as it can be tricky. This feature would be of use to many PHP developers with varying levels of experience and would complete the mbstring extension.
 +
 +One of use case is "trim Byte Order Mark". I think mb_ltrim would be work:
 +
 +<code>
 +mb_ltrim($string, "\u{FEFF}\u{FFFE}");
 +</code>
  
 ===== Proposal ===== ===== Proposal =====
Line 66: Line 72:
 </code> </code>
  
-Other symbols:+Other symbols (included in regex \s):
 <code> <code>
 U+0085 NEXT LINE (NEL) U+0085 NEXT LINE (NEL)
Line 78: Line 84:
     *  Difficult to search     *  Difficult to search
     * Difficult to store in memory     * Difficult to store in memory
 +    * Mapping with other character codes may be incompatible
 +      * For example, to express Hiragana, UTF-8 uses [あ-ゞ], EUC-JP [あ-ゝゞ], and Shift_JIS [あ-ん].
 +
 +
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 104: Line 114:
 ===== Open Issues ===== ===== Open Issues =====
 https://github.com/php/php-src/issues/9216 https://github.com/php/php-src/issues/9216
- 
-===== Unaffected PHP Functionality ===== 
-List existing areas/features of PHP that will not be changed by the RFC. 
- 
-This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise. 
  
 ===== Future Scope ===== ===== Future Scope =====
Line 116: Line 121:
 Include these so readers know where you are heading and can discuss the proposed voting options. Include these so readers know where you are heading and can discuss the proposed voting options.
  
-===== Patches and Tests ===== +===== Voting =====
-Links to any external patches and tests go here.+
  
-If there is no patchmake it clear who will create a patch, or whether a volunteer to help with implementation is needed. +<doodle title="Multibyte for trim function mb_trimmb_ltrim and mb_rtrim" auth="Yuya Hamada" voteType="single"  closed="true" closeon="2023-11-17T00:00:00Z"> 
- +   * Yes 
-Make it clear if the patch is intended to be the final patch, or is just a prototype. +   * No 
- +</doodle>
-For changes affecting the core language, you should also provide a patch for the language specification.+
  
 ===== Implementation ===== ===== Implementation =====
 https://github.com/php/php-src/pull/12459 https://github.com/php/php-src/pull/12459
- 
-===== References ===== 
-Links to external references, discussions or RFCs 
  
 ===== Rejected Features ===== ===== Rejected Features =====
 Keep this updated with features that were discussed on the mail lists. Keep this updated with features that were discussed on the mail lists.
rfc/mb_trim.1697612582.txt.gz · Last modified: 2023/10/18 07:03 by youkidearitai