Req #10429 [Opn->Wfx]: Add options for start/end strings for substr()

From: Date: Tue, 17 Feb 2015 08:22:53 +0000
Subject: Req #10429 [Opn->Wfx]: Add options for start/end strings for substr()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190732@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=10429&edit=1 ID: 10429 Updated by: krakjoe@php.net Reported by: sbergmann@php.net Summary: Add options for start/end strings for substr() -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Strings related Operating System: * PHP Version: * Block user comment: N Private report: N New Comment: In the year 2015 (the future, by any standard), we cannot change a core string manipulation function. As mentioned previously, this idea could be RFC'd, but marking the bug as won't fix and closing the issue for now. Thanks for PHPUnit, from the future. Previous Comments: ------------------------------------------------------------------------ [2015-01-15 20:50:41] requinix@php.net Changing a function as important as substr could very well need an RFC. There is a problem to confront first: substr("string", "0", "5") is ambiguous. On the other hand a brand new function, maybe named according to the substr_* pattern already in place, wouldn't be that difficult and shouldn't require an RFC... Compare with MySQL's SUBSTRING_INDEX function. http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_substring-index ------------------------------------------------------------------------ [2015-01-15 13:47:19] ppasindud at gmail dot com Wouldn't this be a Feature/Change Request and require RFC ------------------------------------------------------------------------ [2001-04-21 05:09:31] sbergmann@php.net I am currently using the following PHP Code to get a substring from a string, that is delimited by two given strings, $start and $end: function my_substr($start, $end, &$string) { $start = preg_quote($start); $end = preg_quote($end); preg_match("#$start(.*?)$end#", $string, $result); return $result[1]; } It would be great if PHP's substr() function could handle operations like this, by changing its signature accordingly, maybe to string substr (string string, mixed start [, mixed end]) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=10429&edit=1

« previous php.bugs (#190732) next »