php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67915 Improve strrchr
Submitted: 2014-08-27 14:14 UTC Modified: 2021-09-27 17:15 UTC
Votes:3
Avg. Score:1.7 ± 0.9
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: contact at mathiasstrasser dot com Assigned: cmb (profile)
Status: Wont fix Package: *General Issues
PHP Version: 5.6.0RC4 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: contact at mathiasstrasser dot com
New email:
PHP Version: OS:

 

 [2014-08-27 14:14 UTC] contact at mathiasstrasser dot com
Description:
------------
Hi,

I would like to know if is that possible to add a new argument in a
function strrchr ?
To do the same things of strstr.

strrchr ( string $haystack , mixed $needle [, bool $before_needle = false
] )

before_needle
If TRUE, strrchr() returns the part of the haystack before the first
occurrence of the needle (excluding the needle).

Actually i'm forced to write:

substr ( $haystack, 0, strrpos ( $haystack, $needle ) )


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-08 10:01 UTC] mkurczew at gmail dot com
This would break SRP for PHP more than it currently is and creating yet another built-in function for this would unnecessarily pollute global namespace. Instead of complicating things more by introducing functions/arguments out of the blue, we should endeavor to simplify things. I'm against this.
 [2021-09-27 17:15 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-09-27 17:15 UTC] cmb@php.net
> Actually i'm forced to write:
>
> substr ( $haystack, 0, strrpos ( $haystack, $needle ) )

Given that this use case isn't the most common, this isn't that
bad.  If you need this often, consider to wrap it in a function.

> This would break SRP for PHP more than it currently is […]

That.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 16:01:37 2025 UTC