This is an old revision of the document!
PHP RFC: Add str begin and end functions
- Version: 0.1
- Date: 2016-08-01 (use today's date here)
- Author: Will Hudgins, firstname.lastname@example.org
- Status: Under Discussion
- First Published at: https://wiki.php.net/rfc/add_str_begin_and_end_functions
PHP does not contain functions to test if a string begins or ends with a certain substring. This is currently possible using several other functions, but adding pre-built functions to do this will improve the readability and clarity of PHP code using the function. This feature has been requested multiple times and would be of use to many PHP developers with varying levels of experience.
Add str_begins() and str_ends() functions
boolean str_begins[(string $str, string $search_value [boolean $case_sensitive = true]) boolean str_ends[(string $str, string $search_value [boolean $case_sensitive = true])
str_begins() checks if $str begins with $search_value. It accomplishes this by comparing each character in $search_value with the corresponding character in $str. If any of the characters do not match, it will return false. str_ends() does the same thing except in reverse: it starts at the end of both $str and $search_value and compares each character in $search_value to the corresponding character in $str.
By default, both str_begins() and str_ends() are case sensitive, however passing false as the third parameter to either function will cause PHP to perform a case insensitive comparison as opposed to a case sensitive one.
Backward Incompatible Changes
Proposed PHP Version(s)
Next PHP 7.x release.
Will add the aforementioned functions to all PHP environments.
To Existing Extensions
No new constants.
No changed php.ini settings.
Unaffected PHP Functionality
The only part of PHP that will be effected by this is the string library. This means that strings.c, basic_functions.c, and php_strings.h have all been modified to add the two new functions.
Once this feature is approved and added, it will not need any future improvements.
Proposed Voting Choices
This project requires a 2/3 majority to be approved.
Patches and Tests
After the project is implemented, this section should contain
- the version(s) it was merged to
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
Links to external references, discussions or RFCs
Keep this updated with features that were discussed on the mail lists.