Req #67035 [Com]: wish: str_ends() and str_begins()

From: Date: Mon, 14 Apr 2014 12:59:17 +0000
Subject: Req #67035 [Com]: wish: str_ends() and str_begins()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185243@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67035&edit=1 ID: 67035 Comment by: malalaimo923 at gmail dot com Reported by: php at richardneill dot org Summary: wish: str_ends() and str_begins() Status: Open Type: Feature/Change Request Package: Strings related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Please see this document: http://www.php.net/manual/en/language.types.string.php It is possible to access and modify a character of a string using an index. The String End is: $string[strlen($string)-1]; The String Start is: $string[0]; Previous Comments: ------------------------------------------------------------------------ [2014-04-06 15:32:04] php at richardneill dot org Description: ------------ It would be really useful to have standard functions: str_ends() and str_begins() These are trivial to implement, but the use for them is so extremely common that they'd be a helpful addition to the standard library. It's also not quite obvious to beginners how to do it - especially for str_ends(). For comparison, Javascript has string.startsWith() and string.endsWith() Examples below. Thank you for your consideration and your time. Test script: --------------- function str_ends($string,$end){ return (substr($string,-strlen($end),strlen($end)) === $end); } function str_begins($string,$start){ return (substr($string,0,strlen($start)) === $start); } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67035&edit=1

« previous php.bugs (#185243) next »