您的位置:首页 > 编程语言 > PHP开发

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

2015-03-17 15:30 1001 查看

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

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息