Home >Backend Development >PHP Tutorial >Replace the Nth occurrence of characters in a string without using regular expressions
For example, there is a string: $a='hello world hello pig hello cat hello dog hello small boy';
Then I want to change the hello that appears for the third time to good-bye, for example: 'hello world hello pig good-bye cat hello dog hello small boy'; In this case, I couldn’t find PHP’s built-in function for a while, and I wrote this simple little function when I was required not to use regular expressions. If you have any recommendations for good built-in functions, please leave a message:) Reprinted from PHP interview questions: http://phpmst.com/
|