您现在的位置是:首页 > PHP函数

李清波 2015-10-01 PHP函数 2193 复制当前网址

substr_replace



PHP substr_replace() 函数

定义和用法

substr_replace() 函数把字符串的一部分替换为另一个字符串。


语法

substr_replace(string,replacement,start,length)


参数描述
string必需。规定要检查的字符串。
replacement必需。规定要插入的字符串。
start

必需。规定在字符串的何处开始替换。

  • 正数 - 在第 start 个偏移量开始替换

  • 负数 - 在从字符串结尾的第 start 个偏移量开始替换

  • 0 - 在字符串中的第一个字符处开始替换

charlist

可选。规定要替换多少个字符。

  • 正数 - 被替换的字符串长度

  • 负数 - 从字符串末端开始的被替换字符数

  • 0 - 插入而非替换


提示和注释

注释:如果 start 是负数且 length 小于等于 start,则 length 为 0。


例子

<?php
echo substr_replace("Hello world","earth",6);
?>

输出:

Hello earth


文章来源:http://liqingbo.com/blog-884.html

上一篇:trim

下一篇:substr_count

评论