#50434 [Opn->Ana]: add string functions str_startswith and str_endswith for convenience
| From: | rasmus@php.net | Date: | Wed, 09 Dec 2009 23:48:49 +0000 |
| Subject: | #50434 [Opn->Ana]: add string functions str_startswith and str_endswith for convenience | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-145602@lists.php.net to get a copy of this message | ||
ID: 50434
Updated by: rasmus@php.net
Reported By: mail at daniel-faber dot de
-Status: Open
+Status: Analyzed
Bug Type: Feature/Change Request
PHP Version: 5.2.11
New Comment:
Isn't it super trivial given the way substr works in PHP?
startswith:
substr($haystack,0,strlen($prefix)) == $prefix
endswith:
substr($haystack,-strlen($suffix)) == $suffix
Usually we add things to core that can't be done with a single trivial
call in PHP. The only thing you save is the strlen call, and you can
hardcode that to avoid it.
Previous Comments:
------------------------------------------------------------------------
[2009-12-09 23:39:58] mail at daniel-faber dot de
Description:
------------
Please add these two string functions for convenience:
boolean str_startswith($string, $prefix)
// true if $string starts with $prefix, false otherwise
boolean str_endswith($string, $suffix)
// true if $string ends with $suffix, false otherwise
Of course one can easily write these functions in PHP, but having them
in the PHP core would be nice. You find them in other languages too:
Java: string.startsWith(prefix) and string.endsWith(suffix)
Python: string.startswith(prefix) and string.endswith(suffix)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50434&edit=1