php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #10429 Add options for start/end strings for substr()
Submitted: 2001-04-21 05:09 UTC Modified: 2015-02-17 08:22 UTC
Votes:3
Avg. Score:2.3 ± 0.9
Reproduced:0 of 1 (0.0%)
From: sbergmann@php.net Assigned:
Status: Wont fix Package: Strings related
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sbergmann@php.net
New email:
PHP Version: OS:

 

 [2001-04-21 05:09 UTC] 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])

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-29 11:48 UTC] jani@php.net
-Summary: Improving substr() +Summary: Add options for start/end strings for substr() -Package: Feature/Change Request +Package: Strings related -PHP Version: 4CVS, 5CVS (2004-04-13) +PHP Version: *
 [2015-01-15 13:47 UTC] ppasindud at gmail dot com
Wouldn't this be a Feature/Change Request and require RFC
 [2015-01-15 20:50 UTC] 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-02-17 08:22 UTC] krakjoe@php.net
-Status: Open +Status: Wont fix
 [2015-02-17 08:22 UTC] krakjoe@php.net
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.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 06:01:23 2020 UTC