Below I have summarized some character replacement methods in php development, including direct replacement without regular expressions or replacement with regular expressions, and replacement using php built-in functions. For example, there is a string: $ a' helloworldhellopighellocathellodoghellosmallboy
Below I have summarized some character replacement methods in php development, including direct replacement without regular expressions or replacement with regular expressions, and replacement using php built-in functions.
For example, there is a string: $ a = 'Hello world hello pig hello cat hello dog hello small boys ';
Then we want to change the 3rd hello appearance to good-bye, for example:
'Hello world hello pig good-bye cat hello dog hello small boys ';
In this case, I will not find the PHP built-in function at half past one, and I wrote this simple small function when the regular expression is not required, if you have recommended built-in functions, leave a message :)
The instance code is as follows:
-