Req #10429 [Opn]: Add options for start/end strings for substr()
| From: | requinix@php.net | Date: | Thu, 15 Jan 2015 20:50:42 +0000 |
| Subject: | Req #10429 [Opn]: Add options for start/end strings for substr() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189979@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: requinix@php.net
Reported by: sbergmann@php.net
Summary: Add options for start/end strings for substr()
Status: Open
Type: Feature/Change Request
Package: Strings related
Operating System: *
PHP Version: *
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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