php substr_replace函数怎么用-php教程

资源魔 25 0
php substr_replace函数用于交换字符串中某串为另外一个字符串,其语法是substr_replace(string,replacement,start,length)。

php substr_replace函数怎样用?

作用:交换字符串中某串为另外一个字符串。

语法:

substr_replace(string,replacement,start,length)

参数:

string 必须。规则要反省的字符串。

replacement 必须。规则要拔出的字符串。

start 必须。规则正在字符串的那边开端交换。负数 - 正在字符串中的指定地位开端交换,正数 - 正在从字符串末端的指定地位开端交换,0 - 正在字符串中的第一个字符处开端交换。

length 可选。规则要交换几何个字符。默许是与字符串长度相反。负数 - 被交换的字符串长度,正数 - 示意待交换的子字符串末端处间隔 string 结尾的字符个数。0 - 拔出而非交换

阐明:

把字符串的一局部交换为另外一个字符串。假如 start 参数是正数且 length 小于或许等于 start,则 length 为 0。该函数是二进制平安的。

php substr_replace()函数应用示例1

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

输入:

Hello php.cn

php substr_replace()函数应用示例2

<?php
$i = "i like JavaScript";
echo substr_replace($i,"php",7);
?>

输入:

i like php

以上就是php substr_replace函数怎样用的具体内容,更多请存眷资源魔其它相干文章!

标签: php开发教程 php开发资料 php开发自学 php substr_replace

抱歉,评论功能暂时关闭!