Re: RFC Posted for str_begins and str_ends functions
| From: | Lauri Kenttä | Date: | Wed, 03 Aug 2016 07:59:24 +0000 |
| Subject: | Re: RFC Posted for str_begins and str_ends functions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94813@lists.php.net to get a copy of this message | ||
Hello,
I only saw you mention strpos, preg_match and substr as (slower) alternatives. However, there's already a function called substr_compare which is meant for just this kind of comparisons but which is more general than your RFC.
function str_begins($a, $b) {
return substr_compare($a, $b, 0, strlen($b)) === 0;
}
function str_ends($a, $b) {
return substr_compare($a, $b, -strlen($b)) === 0;
}
--
Lauri Kenttä