|  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
Avg. Score:2.3 ± 0.9
Reproduced:0 of 1 (0.0%)
From: Assigned:
Status: Wont fix Package: Strings related
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-29 11:48 UTC]
-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]
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.
 [2015-02-17 08:22 UTC]
-Status: Open +Status: Wont fix
 [2015-02-17 08:22 UTC]
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-2021 The PHP Group
All rights reserved.
Last updated: Thu Jul 29 20:01:24 2021 UTC