Re: New string functions: str_startswith() and str_endswith()
| From: | D. Dante Lorenso | Date: | Mon, 21 Jul 2008 20:52:28 +0000 |
| Subject: | Re: New string functions: str_startswith() and str_endswith() | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-39147@lists.php.net to get a copy of this message | ||
Jani Taskinen wrote:
Paweł Stradomski kirjoitti:I'd like to have such a function in PHP, but when you think about how easy it is to create without bloating the PHP core, it's easy enough to do without it. Here's what I do using my own string library: if (LS_Util_String :: ends_with($path, '.php')) { ... } It's a bit longer, but all my functions are longer for good reason: http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/ -- DanteW liście Rasmus Lerdorf z dnia poniedziałek, 21 lipca 2008:You people are funny..It also isn't any shorter: if(str_endswith($path,'.php')) vs. if(substr($path,-4)=='.php')Only if comparing to a static string, but not for this case: if (substr($path, -strlen($extension)) == $extension) Readability would also increase.