Home  >  Article  >  Backend Development  >  PHP string replacement function substr_replace() usage example_PHP tutorial

PHP string replacement function substr_replace() usage example_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:021038browse

Usage examples of php string replacement function substr_replace()

This article mainly introduces the usage of php string replacement function substr_replace(), and analyzes the use of substr_replace function in php with examples. The skills have certain reference value. Friends who need them can refer to them

The example in 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

?

1

2

3

4

5

6

7

$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");

?>

1 2

3

4

5

6

1

2

3

Warning: System will shutdown in 15 minutes!

(10 minutes later)

Warning: System will shutdown in 5 minutes!

7

$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
?
1 2 3 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. http://www.bkjia.com/PHPjc/969352.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969352.htmlTechArticlephp string replacement function substr_replace() usage example This article mainly introduces the php string replacement function substr_replace() Usage, examples analyze the usage skills of substr_replace function in php...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn