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

From: Date: Sun, 06 Apr 2014 15:32:05 +0000
Subject: Req #67035 [NEW]: wish: str_ends() and str_begins()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185127@lists.php.net to get a copy of this message
From: php at richardneill dot org Operating system: PHP version: Irrelevant Package: Strings related Bug Type: Feature/Change Request Bug description:wish: str_ends() and str_begins() 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 bug report at https://bugs.php.net/bug.php?id=67035&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67035&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67035&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67035&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=67035&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=67035&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=67035&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=67035&r=needscript Try newer version: https://bugs.php.net/fix.php?id=67035&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=67035&r=support Expected behavior: https://bugs.php.net/fix.php?id=67035&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=67035&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=67035&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=67035&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67035&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=67035&r=dst IIS Stability: https://bugs.php.net/fix.php?id=67035&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=67035&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=67035&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=67035&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=67035&r=mysqlcfg

« previous php.bugs (#185127) next »