php将身份证号码中间隐藏的实现方法:首先创建一个PHP示例文件;然后通过正则表达式“preg_replace($pattern, $replacement, $string);”方式实现将身份证号码中间用星号替换隐藏即可。
本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
php实现替换手机号中间数字为*号及隐藏IP最后几位的方法
本文实例讲述了php实现替换手机号中间数字为*号及隐藏IP最后几位的方法。分享给大家供大家参考,具体如下:
$string = "13826589549"; $pattern = "/(\d{3})\d\d(\d{2})/"; $replacement = "\$1****\$3"; print preg_replace($pattern, $replacement, $string);
输出的结果:138****9549
这个匹配结果是我想要的,但是这个匹配模式是错误的,它只能匹配7个,剩余4个数字匹配不到,就显示出来了,还有\$3根本就不存在
正确的写法应该是
$string = "13826589549"; $pattern = "/(\d{3})\d{4}(\d{4})/"; $replacement = "\$1****\$2"; print preg_replace($pattern, $replacement, $string);
当然还可以使用截取字符串的方法,隐藏中间的数字
function suohao($phone){ $p = substr($phone,0,3)."****".substr($phone,7,4); return $p; } echo suohao($string);
输出结果:138****9549
隐藏IP最后几位为*
<?php echo preg_replace("/[^\.]{1,3}$/","*",$ip); ?>
【推荐学习:《PHP视频教程》】
The above is the detailed content of How to hide the ID number in the middle in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
