substr_replace深入研究

本文详细介绍了PHP中substr_replace函数的使用方法,包括如何替换字符串中的子串,以及不同参数设置下的应用场景。通过示例代码,读者可以快速上手并应用到实际项目中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

substr_replace非常有用,替换子字符串

直接上代码。由于我的sublime text暂时只支持英文,所以抱歉


<?php
/**
 substr_replace study
 @param substr_replace($old_string, $mew_substring, $start, $length);
 

*/
$str1 = "my pet is a blue dog.";

echo substr_replace($str1, "test", 12);
echo "<br>";
echo substr_replace($str1, "test", 12, 4);

$phone = "13755558888";
$replacePhone = substr_replace($phone, "XXXX", 3, 4);
echo $replacePhone;
echo "<br>";
// negative situation
echo substr_replace("my test just here", "bill", -6);//should show "my test jusbill"
echo "<br>";
echo substr_replace("my test just here", "bill", -6, 5); //should show "my test jusbille"
//0 0 situation
echo "<br>";
echo substr_replace("my test just here", "bill", 0, 0); // should show "billmy test just here"


?>

基本上substr_replace完全可以掌握了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值