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程序设计有所帮助。

相关文章

MongoDB在PHP中的常用操作小结

$mongodb = new Mongo(); //$connection = new Mongo( "$dburl:$port" ); // connect to a remote h...

PHP+sqlite数据库操作示例(创建/打开/插入/检索)

本文实例讲述了PHP+sqlite数据库操作的方法。分享给大家供大家参考,具体如下: SQLite是一款轻型的数据库,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占...

php魔术方法功能与用法实例分析

本文实例讲述了php魔术方法功能与用法。分享给大家供大家参考,具体如下: <?php //php中的魔术方法 header('content-type:text/htm...

PHP中用hash实现的数组

PHP中使用最多的非Array莫属了,那Array是如何实现的?在PHP内部Array通过一个hashtable来实现,其中使用链接法解决hash冲突的问题,这样最坏情况下,查找Arra...

php通过rmdir删除目录的简单用法

本文实例讲述了php通过rmdir删除目录的简单用法。分享给大家供大家参考。具体分析如下: php可以通过rmdir()函数删除服务器上的目录,下面代码里用到了is_dir()函数,该函...