substr_replace()函数:将手机号中间4位隐藏为*号

本文介绍了 PHP 中的 substr_replace 函数,详细解释了如何使用该函数来替换字符串中的子串,并提供了具体的代码示例。

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

<?php

$mobile = "15810320826"; 
echo substr_replace($mobile,'****',3 , 4); 

?>

 

substr_replace

(PHP 4, PHP 5)

substr_replace — 替换字符串的子串

说明

mixed substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ] )

substr_replace() 在字符串 string 的副本中将由 start 和可选的 length 参数限定的子字符串使用 replacement 进行替换。

参数

 

string

输入字符串。

An array of strings can be provided, in which case the replacements will occur on each string in turn. In this case, the replacement,start and length parameters may be provided either as scalar values to be applied to each input string in turn, or as arrays, in which case the corresponding array element will be used for each input string.

replacement

替换字符串。

start

如果 start 为正数,替换将从 string 的 start 位置开始。

如果 start 为负数,替换将从 string 的倒数第 start 个位置开始。

length

如果设定了这个参数并且为正数,表示 string 中被替换的子字符串的长度。如果设定为负数,它表示待替换的子字符串结尾处距离string 末端的字符个数。如果没有提供此参数,那么它默认为 strlen( string ) (字符串的长度)。当然,如果 length 为 0,那么这个函数的功能为将 replacement 插入到 string 的 start 位置处。

返回值

返回结果字符串。如果 string 是个数组,那么也将返回一个数组。

转载于:https://www.cnblogs.com/kenshinobiy/p/4501352.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值