Is there a way to customize the str_replace function so that instead of replacing ALL occurences of the string needle, it will only replace the first occurence? or maybe the last occurence? or the n th occurence?
Well, there are functions to find the first and last occurances of a string.
They are strchr() and strrchr(). The first one finds the first occurance of a character in a string, and the second finds the last occurange of a character in a string.
There are no functions to find the nth ocurrance of the string, so you would have to write one.
Hope this helps.
-Vic vic cherubini
krs-one@cnunited.com
It looks like strchr() and strrchr() will only find the needle. What I really need is a function that will replace the needle.
As far as replacing the nth occurence, has anybody out there written a custom function like this before? I've searched the forum archives with no luck.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.