I’m looking for a modified version of str_ireplace (case-insensitive) that would replace ONLY ONCE.
I read online it’s doable with preg or other techniques but I’m looking for a generic function I can re-use.
Bonus: the use will be to add a link anchor tag around the word, so it would be nice if it could somehow keep the capitalization of the original word.
It sounds like you definitely want
preg_replace(). If you would like you can create a user defined function:but there is kind of no reason to do this rather than
preg_replace(). This call is really no more complex than astr_ireplace()call.The last parameter was added for limiting to 1 occurrence.