Skip to content

Instantly share code, notes, and snippets.

@leavyli
Last active March 2, 2018 15:24
Show Gist options
  • Save leavyli/41203f8f291db792d079db0c974dd958 to your computer and use it in GitHub Desktop.
Save leavyli/41203f8f291db792d079db0c974dd958 to your computer and use it in GitHub Desktop.
替换手机星号
<?php
//输出结果string(115) "mobile: 13929****47,13929****47,13929****47,13929****47,1****3,13929****47,13929****47, name:liwei, moblie: 1****6"
$s = "mobile: 13929571847,13929527847,13929517847,13929575847,123,13929575847,13929575847, name:liwei, moblie: 12636";
$p =[
"/(.*?)(\d)(\d{1,4})(\d{1,2},)/",
"/(.*?)(\d)(\d{1,4})(\d{1,2}$)/",
];
$r = [
'\1\2****\4',
'\1\2****\4',
];
$res = preg_replace($p, $r, $s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment