Home > Article > Backend Development > PHP string replacement function substr_replace() usage example, substrreplace_PHP tutorial
This article describes the usage of php string replacement function substr_replace(). Share it with everyone for your reference. The specific analysis is as follows:
substr_replace is used to replace the substring at the specified position in the specified string
<?php $string = "Warning: System will shutdown in NN minutes!"; $pos = strpos($string, "NN"); print(substr_replace($string, "15", $pos, 2)."\n"); sleep(10*60); print(substr_replace($string, "5", $pos, 2)."\n"); ?>
Enter the above code and the following results
Warning: System will shutdown in 15 minutes! (10 minutes later) Warning: System will shutdown in 5 minutes!
I hope this article will be helpful to everyone’s PHP programming design.