New string functions: str_startswith() and str_endswith()
| From: | Martin Jansen | Date: | Sat, 19 Jul 2008 12:55:57 +0000 |
| Subject: | New string functions: str_startswith() and str_endswith() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-39099@lists.php.net to get a copy of this message | ||
Attached you'll find a patch against PHP_5_3 that implements two new
string functions:
str_startswith(haystack, needle [, case_sensitivity])
checks if haystack starts with needle. The check is performed
case-insensitively, but this can be overridden by passing TRUE as the
value for the third parameter. The second function
str_endswith(haystack, needle [, case_sensitivity])
checks if haystack ends with needle and has the same semantics
regarding case-sensitivity.
I admit that both functions can be easily implemented in userland with
already existing functions. At the same time I like them because they
make the common tasks of prefix and suffix checks easy and convenient.
I won't mind if you guys don't like the idea (I did it mainly for
personal entertainment and learning about PHP internals), but if you
are interested I'll happily provide a patch for HEAD, too. Also since
this is my first foray into PHP internals, comments and corrections
are more then appreciated.
Martin
Attachment: [text/x-diff] php5.3-strings.patch
Attachment: [text/x-diff] php5.3-strings.patch