Tools, FAQ, Tutorials:
Replacing a Substring in PHP
How To Replace a Substring in a Given String?
✍: FYIcenter.com
If you know the position of a substring in a given string, you can replace that substring by another string by using the substr_replace() function. Here is a PHP script on how to use substr_replace():
<?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"); ?>
This script will print:
Warning: System will shutdown in 15 minutes! (10 minutes later) Warning: System will shutdown in 5 minutes!
Like substr(), substr_replace() can take negative starting position counted from the end of the string.
⇒ Reformatting a Paragraph of Text in PHP
2016-10-13, ∼2472🔥, 0💬
Popular Posts:
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
How to use .NET CLR Types in Azure API Policy? By default, Azure imports many basic .NET CLR (Common...
How to create a "Sign-up or Sign-in" user flow policy in my Azure AD B2C directory? If you want to b...
How to use the "forward-request" Policy Statement to call the backend service for an Azure API servi...
Where to find tutorials on Microsoft Azure services? Here is a large collection of tutorials to answ...