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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
40 - 23 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC