php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #24113 new function "str_replace_once"
Submitted: 2003-06-10 08:32 UTC Modified: 2003-06-10 08:35 UTC
Votes:4
Avg. Score:4.0 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: dave at netready dot biz Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.3.1 OS: Linux
Private report: No CVE-ID: None
 [2003-06-10 08:32 UTC] dave at netready dot biz
Hi, 

I have been using str_replace to search and replace over large strings.  Replacing strings I know for certain only occur once.  I was just thinking that maybe if there was a str_replace_once function that would stop searching after it had replaced one instance of search string this could save considerable time checking the rest of the string.

To make it really useful it could have a backward/forward option so If you knew the string you are searching for occurs near the end of your string you could search backwards for it.  Or would that be a separate function? I'm not sure what your guidlines are on that.

This would have even more speed impact on str_ireplace because by it's nature it is slower, so maybe a str_ireplace_once would be a good idea too?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-10 08:35 UTC] derick@php.net
preg_replace already supports this:

mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit])

regards,
Derick
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 08 14:00:02 2025 UTC