php字符串替换函数substr_replace()用法实例

yipeiwu_com6年前PHP代码库

本文实例讲述了php字符串替换函数substr_replace()用法。分享给大家供大家参考。具体分析如下:

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

上面代码输入如下结果

Warning: System will shutdown in 15 minutes!
(10 minutes later)
Warning: System will shutdown in 5 minutes!

希望本文所述对大家的php程序设计有所帮助。

相关文章

在PHP中养成7个面向对象的好习惯

在 PHP 编程早期,PHP 代码在本质上是限于面向过程的。过程代码 的特征在于使用过程构建应用程序块。过程通过允许过程之间的调用提供某种程度的重用。 但是,没有面向对象的语言构造,程序...

php array_unique之后json_encode需要注意

例如:array_unique(array(1, 1, 2)); 他的结果是 array(2) { [0]=> int(1) [2]=> int(2) } 这就不是numer...

15种PHP Encoder的比较

15种PHP Encoder的比较

来源:http://www.encodercompare.com/ 似乎没有一个免费且好用的。。  ...

php文件操作相关类实例

本文实例讲述了php文件操作相关类。分享给大家供大家参考。具体如下: <?php class file_dir { function check_exist($...

详解PHP版本兼容之openssl调用参数

背景与问题解决方式 老项目重构支付宝部分代码整合支付宝新的sdk时发现验签总是失败,才发现是open_verify最后的参数传输问题。而open_sign同样如此。本文主要说明open_...