如何巧妙隐藏身份证号中的6位数字以保护隐私?

2026-04-06 15:481阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计440个文字,预计阅读时间需要2分钟。

如何巧妙隐藏身份证号中的6位数字以保护隐私?

隐藏方法:1. 使用substr_replace($str, str_repeat('*', 6), -6)语句,可隐藏后6位;2. 使用substr_replace($str, str_repeat('*', 6), 6, 6)语句,可隐藏中间6位。本教程操作环境:Windows 7系统、PHP 7.1版、DELL G系列。

隐藏方法:1、用“substr_replace($str,str_repeat("*",6), -6)”语句,可隐藏后6位;2、用“substr_replace($str,str_repeat("*",6),6,6)”语句,可隐藏中间6位。

本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑

在PHP中,可以使用substr_replace()函数和substr_replace() 函数来隐藏身份证号并将隐藏的数字替换成星号。

1、隐藏后6位身份证号

<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),-6); ?>

2、隐藏中间6位身份证号

<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),6,6); ?>

3、隐藏前6位身份证号

<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),0,6); ?>

说明:

substr_replace() 函数把字符串的一部分替换为另一个字符串;会从指定位置开始替换指定长度的字符串。

str_repeat() 函数把字符串重复指定的次数。

上例中,就是将星号“*”字符重复指定次数(和需要隐藏的位数一致),将该生产的子串作为替换值,替换掉字符串中一部分。

推荐学习:《PHP视频教程》

以上就是php怎么隐藏6位身份证号的详细内容,更多请关注自由互联其它相关文章!

如何巧妙隐藏身份证号中的6位数字以保护隐私?

本文共计440个文字,预计阅读时间需要2分钟。

如何巧妙隐藏身份证号中的6位数字以保护隐私?

隐藏方法:1. 使用substr_replace($str, str_repeat('*', 6), -6)语句,可隐藏后6位;2. 使用substr_replace($str, str_repeat('*', 6), 6, 6)语句,可隐藏中间6位。本教程操作环境:Windows 7系统、PHP 7.1版、DELL G系列。

隐藏方法:1、用“substr_replace($str,str_repeat("*",6), -6)”语句,可隐藏后6位;2、用“substr_replace($str,str_repeat("*",6),6,6)”语句,可隐藏中间6位。

本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑

在PHP中,可以使用substr_replace()函数和substr_replace() 函数来隐藏身份证号并将隐藏的数字替换成星号。

1、隐藏后6位身份证号

<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),-6); ?>

2、隐藏中间6位身份证号

<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),6,6); ?>

3、隐藏前6位身份证号

<?php header("Content-type:text/html;charset=utf-8"); $str = "371515111111116042"; echo substr_replace($str,str_repeat("*",6),0,6); ?>

说明:

substr_replace() 函数把字符串的一部分替换为另一个字符串;会从指定位置开始替换指定长度的字符串。

str_repeat() 函数把字符串重复指定的次数。

上例中,就是将星号“*”字符重复指定次数(和需要隐藏的位数一致),将该生产的子串作为替换值,替换掉字符串中一部分。

推荐学习:《PHP视频教程》

以上就是php怎么隐藏6位身份证号的详细内容,更多请关注自由互联其它相关文章!

如何巧妙隐藏身份证号中的6位数字以保护隐私?