您的位置:首页 > 其它

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

2015-05-13 18:48 316 查看
<?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
是个数组,那么也将返回一个数组。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐