PHP将部分内容替换成星号

在最近的项目中,会碰到到某人的手机号码隐藏中间几位,身份证号码只显示末尾4位的需求。当时一开始是网上搜索了一下,看到有人是用substr_replace这个函数来替换的,后面我也用了这个函数,但在用的时候不是很好用。

一、substr_replace

先来看看这个函数的语法:

substr_replace(string,replacement,start,length)
参数 描述
string 必需。规定要检查的字符串。
replacement 必需。规定要插入的字符串。
start

必需。规定在字符串的何处开始替换。

  正数 - 在第 start 个偏移量开始替换

  负数 - 在从字符串结尾的第 start 个偏移量开始替换

  0 - 在字符串中的第一个字符处开始替换

charlist

可选。规定要替换多少个字符。

  正数 - 被替换的字符串长度

  负数 - 从字符串末端开始的被替换字符数

  0 - 插入而非替换

1、当start与charlist都为正数的时候,非常好理解,也很符号人的逻辑,start是从0开始的,如下图,根据条件,绿色的将是要被替换的元素

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR8AAACCCAIAAADwulszAAAJOklEQVR4nO2dPXLjuhJGsQsuwgEDLsKhV4CEe1B+QzHhEpxOSgdcgate6kSBWTf3MPZbAG5ACwKpHzfE7rHlOacmsD2eTyDQh/gRp+QCANjgvroBAD8W7AKwArsArMAuACuwC8AK7AKwArsArMAuACuwC8AK7AKwYmnX/wBAxjV2qZlLMsl/dzJ2kUyyVTJ2kUyyVTJ2kUyyVTJ2kUyyVTJ2kUyyVTJ2kUyyVTJ2kUyyVTJ2kUyyVfIqu/qmGVRbE0IYd33hPmg7UbwwuW/qfXDR70bF5EjrK9U2j3UZO0PabHmbW19NuZVvJb8vSU6Hb6JuepXkMBtBu9qohCVtaNd+YKRNESaPu74s63H/daFXT0PXxhoaulbY8iy7hq7VHvWxaR7lDchJDq2vprpX7+dUp9Z7rX5OR029zcW+6tKv1yevmbuGStuuvqnnYyOaCnJ7UN7yrN7wflOXhapdQyO48V+RnN7FdJPT5cy46zey9l9XG1qz4qLMFKvu29mVziqK15myuL+qJLfeD2G8FbsWlaqYnCKcuITJ6eojhND6e6W5a6zLMo0Sds7t2bXIv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g3LSSaSmrO49tzrutDOk3bl9vMFWBN+P86sDM8tZk4M4RjK4vDD43v8yYXKF+y75nNRymm7rrquC+08+XN5P1/uH9T6lnx2qnFYKYUQTo3iYjVytV2fcrI6pyITkWnXddd1rp0Xfh7/9nI/X2KY/bLWoS6s5lRpep98Mx+5XX+o0a4LYbr7Vodfdi50z6F53Eedt2uR8ymL+vtovtyuxXJuDH5zopHRruuuK+TYldXPZxlDeT/7Nl4XfDWnSnO2CDnaq8RjrvQdzHgQFx99WKxkjmvxOOcc6ebn+Pflds2amhxjLM8A9yuu3Ota/FV0KcYufp7bz5LOcY6Dje/DLTyrcYEstQD+LFQngBXYBWAFdgFYgV0AVmAXgBXYBWAFdgFY8R9sJVM/RXv+EgAAAABJRU5ErkJggg==" alt="" />

2、当start为负数,charlist为正数的时候,也挺好理解的

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR4AAACBCAIAAACZ7EKjAAAJh0lEQVR4nO2dPXKjShRG2QWLcEDAIhx6BSTsQfkLRcISnE6KAxYw5aoXjhMF7prcQ+xZQL8ACzWtH25L91qW3znlwPbgT82lD/0jppR5ADAgu3YDAL4nqAVgAmoBmIBaACagFoAJqAVgAmoBmIBaACagFoAJqAVgwkytfwFARrJayuaSTPL/NRm1SCbZJBm1SCbZJBm1SCbZJBm1SCbZJBm1SCbZJBm1SCbZJBm1SCbZJBm1SCbZJPl8tfqmcapN8d4Pmz7PPmg7UbwwuW/qbXDebwbF5Im2KlXbPNTFVAxps+VtbqtyzC2rVnK8JDm8fCN106sk+9kVtOsbpbBLW6m1vSrSdgiTh01fFPWw/T7X60yua6cO5LpW2PIktVzXal/yoWke5Q1ISfZtVY6dXr3OoUttVWnVObxq6m3Ot70u/P7y5LNHLVdqq9U39fzCiAaB1PLJW55Ujapa1UWuqpZrBLf8M5LDW5hucjiRGTb9Stb+8/qG1ngYdTPFXve11ArHE8WTDInurCrJbVU5P9yKWlE3VUwOEQ5ZwuRw3uG9b6t7pVFrqIsijBI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7anXtTJvwwh+4+bm97uhmP1aVr9p4/ia/iYpGs3l4KuFqJxSgKnd6NPV2rXLW+fqTa6195RLqL2DTs9C6CofUOnYljl3a8EYed7VDUerzk/MD3dFBL9Qmqknq+fpEtVLrfwKmgtfj0ITw2FzlwHUafJHvfrl/Fz84mCivtXw8mCRw/A8Pq3XW+foUtXxK/U/XDa+uysltjN1EyHt/6FJFk42z1UrGxeu9MHDsYdKcFLXOO1+fqFb4r6frfwo3O1hraxfE7HXBqgp+mF+eTb/riF3n/Xh/LXcHZ5nvnn3zuI06rlaUk8x8IleVsw6aoFY0ixt8tdr9fl+t887Xp6iVVP+jRLumwXnBZ7HXBWdzjL11yLR5Fb4dOW2vTQ8xRBOV/Q63n5OMOzV1lKs1O4Vg3yLe8du+Sur5Rv80NXWKjX6fWv+DhKvBzOaBFVjiRp/GOEmSVwA20AsBTEAtABNQC8AE1AIwAbUATEAtABP+A1kmWltPwSAjAAAAAElFTkSuQmCC" alt="" />

3、当start为正数,charlist为负数的时候,这个我一开始理解错了

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAS8AAAD/CAIAAAAv9ccUAAAQDklEQVR4nO2dPXKjSheG2QWLUEDAIhxqBSTswfnNRiQsYW44qRSwAJerbmgnCkx9uU3sWUB/ARZqtf5OQ7d8sJ6nHMga9Ap1n4f+ETVODADoIPnuEwCAL7ARQAvYCKAFbATQAjYCaAEbAbSAjQBawEYALWAjgBawEUAL2AigBWwE0IKfjf8BgIxb2DjiPUgmmWQJ2EgyyVqSsZFkkrUkYyPJJGtJxkaSSdaSjI0kk6wlGRtJJllLMjaSTLKWZGwkmWQtyRFtbKqqDZ3cbZs0+aJei+KFyU1V7oLTZtsFTB6oizzoOXdlNjSG9LTl51wXeZ+bF7XkeEmy3X09ZdUESTYHPRivNnJhSSuycdeR0lMXJnfbJsvKbvc4DVd/7boeaq5d18Iz92rxdl2HrpKuqn7LT8An2dRF3nsSvJ1t/eqiCNXOdq8FP+d0V3X24+nJx8Qb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Jvv9t2zA8aiCojaE69ThnmObZP25ZdyZ7CPDuDgptHNk+Nu3BAdiog1E2DuuNfY+2bikMFbxt9k8OXT5Uz7o169okiUlSs+0u5VyitRImsK9pa9wocrN+NlnqvoXf57LewpHk67BT8ni188QPzk6VAvxtXNcHptk1dOIS2x5Vdnvwa1GYonYnnCMv1YchvtgrN9uZIt8bVZW79dWoz2UurhuPLfVo5/Mf6uqYuW1YNCphlI3nOu9cldjDiFu1p6JGT5zGz7jas0OrbZrz2X0/l/G00bedR8AcVROjZqrnJlcnurYzWbp/8ngMOTmUjV8XHQ5ZHpx/4WkbR30u42Oj8Wln73XjmRz4Vqbt4uxnbsaYU73rzIJG23iW1l2j2i/si1Ka42PjuM9lPG20//VyO4+hPQgJtRkOE/C3sSisXw57dNvsa3q9Nqa/uuf7g5PErJ9N9XsXdd5GJ+cshzPMIj+oaQ8bnellZ4rHEyc52DjucxkfG73a2Rtn/9n6vPB9+Nt4MCk6WmsN24D2N8vDRuVwa4szszqu3eOcs7SX5mZyGw9O1dq2cfdId+/i+7mcfxpOdYh1nvdtZy/sFW8S5zYm8Gfu9+JcxEtFgO+GegXQAjYCaAEbAbSAjQBawEYALWAjgBawEUAL2AigBWwE0AI2Amjh/44/V58Ka9GVAAAAAElFTkSuQmCC" alt="" />

4、当start为负数,charlist为负数的时候,有一个地方需要注意的就是:如果 start 是负数且 length 小于等于 start,则 length 为 0。这个坑挺容易踩到的

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASkAAACACAIAAADYnwhHAAAJmUlEQVR4nO2dP3arOBSH2QWLSEHBIlJ6BWrYg/spTcMS8srX4oIFzMk5U04aiuhM76jOW4CmIMhCtpMruPKF5PedFHGe84sQ90N/4B1nFgAgQSbdAAB+KHAPABngHgAywD0AZIB7AMgA9wCQAe4BIAPcA0AGuAeADHAPABm+cO8fAAANfvdiE4kgGck/PBnuIRnJMslwD8lIlkmGe0hGskwy3EMykmWS4R6SkSyTDPeQjGSZZLiHZCTLJMM9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D0AZIB7AMgA9wCQAe4BIAPcA0AGuAeADHAPABngHgAywD0AZIB7AMgA9wCQAe4BIAPcA0AGuAeADHAPABngHgAywD0AZIB7dLSN+fhbAD7nG7nXNjbLzl+Ez6ePoK5slvG4N0Rlmb362W51ZYuK4a9EocqPJt3/T/9gvpN7T5b8qbdzUCXnuFdXa3HPPy5VMl+zwG0Wu1fXHM3gyOFqyS3u4150zsKj1jYrz6/6DkPf3VjmHtepusxxEzP/6/Ni/YHuMfSbnrwB7t0RmntuPXA+Tzo8wa4u++78Q3ciXU20elyY5bY3n+XEUtfnJd/CAjpXsDcmqNK2z7bIvcZba2OP1/sTgRKu8ZeqRPX/wgPHftK9ILjXNhOv/Mq4cpnUF/WqJy+Vsqqx1tgin8QSbfnkuu6vVZasW/wVl2+IKs/+1NWYP+t47afrvUsnI/r/9kF9OR72HRZ794Tm3q1Tcuvc+0NBWIvXotinOn03USICHQ5QDt+roE9ij9dGuhfb/zPAbPPu0Oact6ZDV06YsUV+/uHlOHB1SsOy3pugF7h34xevuzfreG2Mezam/+f1G8STIHKv5TzXstZeO2fBvGW2e9HocM3pBw4lSM2JcW/e8dpI9/x//bz/56AnIam3rMAIoSKV8l5Mz5M/tWtba4crdHl+c5bZ9tnWT2PUbfeCnGgu1l1+BUe4F0wUjVX7888v3Zt3vDbGvaj+j8bY4nHy0h0vSAyhIifTmIu1kNuC8+/Puk1C9zhIMBe6rMjLnGi8rb/LBRLdvckheJsr4b6lt8cTdbzBPznTgudy3M9j+z8Kf6V6q+tAGr7Rcy2fECUeAHcBRQmADHAPABngHgAywD0AZIB7AMjwP38Kcz3vh4WgAAAAAElFTkSuQmCC" alt="" />

5、charlist为0的时候,就变成插入了,而不是替换,额。。。

用下来,我是感觉不是很顺手,虽然说满足我现在的需求还是可以的,但是如果将来需要一些扩展的话,耍起来挺吃力的,所以就想到自己构造一个,将来用起来也方便。

二、自制的星号替换函数

replaceStar($str, $start, $length = 0)
参数 描述
str 必需。规定要检查的字符串。
start

必需。规定在字符串的何处开始替换。

  正数 - 在第 start 个偏移量开始替换

  负数 - 在从字符串结尾的第 start 个偏移量开始替换

  0 - 在字符串中的第一个字符处开始替换

length

可选。规定要替换多少个字符。

  正数 - 被替换的字符串长度,从左往右

  负数 - 被替换的字符串长度,从右往左

  0 - 如果start为正数,从start开始向左到最后

     - 如果start为负数,从start开始向右到最后

前面的两个参数与上面的一样,最后的参数与上面不同

1、当start与length都为正数,与substr_replace表现的一样

2、当start为负数,length为正数,与substr_replace表现的一样

 
substr_replace
replaceStar
start为正数,长度为负数

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASgAAACCCAIAAAB6lcJyAAAJ/klEQVR4nO2dP1LjThOGdQsdwoECHYLQJ5hEdyDf0Ep0BDYklQMdgKLqC5fEAaovN4rhAPMLhMejsY275R5aA+9TBLDrfTya6Vfzx9oiswCAbyfTbgAAvxEEDwAFEDwAFEDwAFAAwQNAAQQPAAUQPAAUQPAAUADBA0ABBA8ABb4K3v8AADSEg8fVEYEZ5l9uRvBghlnBjODBDLOCGcGDGWYFM4IHM8wKZgQPZpgVzAgezDArmBE8mGFWMCN4MMOsYBYLXlfXPfnFRPOw6/Lsk6Yl6Ynmrq4O4rzbDYJmR2NK0TYPVeE6g9psepsbU47e0jSU11PM/vCNVHUnYraTEYxXGyWxpHWCdxgzaiuJ5mHXFUU1HL7P5UqtbxtXXn3bEFvO6ty+baQLYqjrB3oDOGbbmHKMhHg/+0lrjJHqZ3/UxNucH6rO//52c4DUjNeX0sHr6mo6bKQJhNu59JazesOY+6rIRYPX14TpYobZv8HJmv1F0LDr7mntn1cbUnNpUGaCVRew6OD5c1GkLgjuyiLmxpjeDqkELyhiQbMPcbojmv01i7W2MXdCM95QFYWvInbOjwpe4L+TnvTHpTxxS0M3D7vuoe1tlOA9uG2eoHmcLtweT/w2ZDnTHd3cmHLc6IreOsNRa0xJqZAfGzziLW2GWXodP9yb+8Fa8eD5OxnZXc0YuUNT+5KWaubB2z1x+Ojmv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5wDyAPuAeQB9wDyAPuAeQB9wDygHsAecA9gDzgHkAecA8gD7gHkAfcA8gD7gHkAfc+G4MN+fO6cL3cnHvrzhbF/ivkD77NaJttgvhvrykw/aNa7pl6+xaqRicQVLk9956s+K/enqdt/ql71lpT67jn55g6/h4EyVByr20/S47WSLZpid07HK2Oe4Mt6v1Pm56p7xOi4Z7WpT3McQs//+tjGa7IvaN1O+pecB2G2Qtw71MS4p7bP+yv67BsCNc3m37/S3fhXQ+th93GrLSb8aOcUNp2v+W7vOGOurc3oZ79Zv3LVqX3pibG3S/90p1+v6Y+kXPZu+D85vMhdm/dzbzyO/LIbXW+5lncy01tjbGm2/alHyu05YN5wN/bXL7POXRv9pthP2BT71Vpm9kYtq8fbVXNXDo17x3NOTW8s/Phpmez9zkJce/UJTzljD/1Ld07FqW+NNr0s1tABEv3DiYxl+/fX/xazdwrZ3U4u+b8oOZCWG1+YkLWnG4td3hnXV7g0VblbE5YuHd0CaSy35sxaLt3OvCkM56u5+t2IieuDoj3uYk6a1mshQ6v8WKdE+1eMMNyz+kHTi0bxJF5rzq+Bzs5792d3LOlnfeGWbjuERRoIO5FY7wf5tfVX9qt19ZOM2S9f/F0DtE+7aJOu7fICeZgn+mbo+CetW3jvffx+JuaOeMfq5TL/d7h+9Vxb7TV3exH8xCVAwkR9+Js2XNw/uaOQP3zOrcjco9rLNZOhwYe5gTj9fph48rdWwzVN3D/1rxDkeX5rTvP9NeoCyUO3u/JnED8nfapUkBubu65lg8InfQuZ3nYc/H+E26Ir+ReFmZTkNLndXAT4B5AHnAPIA+4B5AH3APIA+4B5AH3APLwP3QzjdZpI491AAAAAElFTkSuQmCC" alt="" />

 start为正数,长度为0 做插入操作  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAB9CAIAAACNhilKAAAJ30lEQVR4nO2dPXKjShRG2QWLUEDAIhxqBSTswfmEImEJM6FTCFiAS1UvtBIFppxLxPIC+gVYraahpdtwL572fKcceFwzx033/egfmFKkAABiR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1ve7MFhXc8nGreOYRyVMr6oZt8wPaFtq61tm8u6TEMR10+jqrbwXM83lzsLe3YMARP67Kw3nt//U1NAmOfo6TuHu/y/foFD/fx7htCOU5WOxcbCXPgaZ/OmV2QeSDDWTJdVsmlxxur0C+rlh48Z6h2/M5vzToFcU9rzVLQXvv1OttO/ivO+73poQ0VT67cGyt6cuUTfNtdOFcOP7AHA2d+RvBEsI92ceQIpiB4AAiA4AEgAIIHgAAIHgAC/A80yVQvrf+KTgAAAABJRU5ErkJggg==" alt="" />

三、源码分享

public static function replaceStar($str, $start, $length = 0)
{
$i = 0;
$star = '';
if($start >= 0) {
if($length > 0) {
$str_len = strlen($str);
$count = $length;
if($start >= $str_len) {//当开始的下标大于字符串长度的时候,就不做替换了
$count = 0;
}
}elseif($length < 0){
$str_len = strlen($str);
$count = abs($length);
if($start >= $str_len) {//当开始的下标大于字符串长度的时候,由于是反向的,就从最后那个字符的下标开始
$start = $str_len - 1;
}
$offset = $start - $count + 1;//起点下标减去数量,计算偏移量
$count = $offset >= 0 ? abs($length) : ($start + 1);//偏移量大于等于0说明没有超过最左边,小于0了说明超过了最左边,就用起点到最左边的长度
$start = $offset >= 0 ? $offset : 0;//从最左边或左边的某个位置开始
}else {
$str_len = strlen($str);
$count = $str_len - $start;//计算要替换的数量
}
}else {
if($length > 0) {
$offset = abs($start);
$count = $offset >= $length ? $length : $offset;//大于等于长度的时候 没有超出最右边
}elseif($length < 0){
$str_len = strlen($str);
$end = $str_len + $start;//计算偏移的结尾值
$offset = abs($start + $length) - 1;//计算偏移量,由于都是负数就加起来
$start = $str_len - $offset;//计算起点值
$start = $start >= 0 ? $start : 0;
$count = $end - $start + 1;
}else {
$str_len = strlen($str);
$count = $str_len + $start + 1;//计算需要偏移的长度
$start = 0;
}
} while ($i < $count) {
$star .= '*';
$i++;
} return substr_replace($str, $star, $start, $count);
}

不擅长算法,这里就用很普通的逻辑来展示啦,没有用到啥数学公式。

1、if($start >= 0)这里做start大于等于0与小于0的分支

2、在start 的分之中,分别再做length 大于0,小于0和等于0的三个分支

3、最后计算出start、count和要替换的星号字符串,最后计算出的start与count都是正数,运用substr_replace做替换

四、单元测试

public function testReplaceStar()
{
$actual = App_Util_String::replaceStar('123456789', 3, 2);
$this->assertEquals($actual, '123**6789'); $actual = App_Util_String::replaceStar('123456789', 9);
$this->assertEquals($actual, '123456789'); $actual = App_Util_String::replaceStar('123456789', 9, 2);
$this->assertEquals($actual, '123456789'); $actual = App_Util_String::replaceStar('123456789', 9, -9);
$this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 9, -10);
$this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 9, -11);
$this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 3);
$this->assertEquals($actual, '123******'); $actual = App_Util_String::replaceStar('123456789', 0);
$this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 0, 2);
$this->assertEquals($actual, '**3456789'); $actual = App_Util_String::replaceStar('123456789', 3, -3);
$this->assertEquals($actual, '1***56789'); $actual = App_Util_String::replaceStar('123456789', 1, -5);
$this->assertEquals($actual, '**3456789'); $actual = App_Util_String::replaceStar('123456789', 3, -3);
$this->assertEquals($actual, '1***56789'); $actual = App_Util_String::replaceStar('123456789', -3, 2);
$this->assertEquals($actual, '123456**9'); $actual = App_Util_String::replaceStar('123456789', -3, 5);
$this->assertEquals($actual, '123456***'); $actual = App_Util_String::replaceStar('123456789', -1, 2);
$this->assertEquals($actual, '12345678*'); $actual = App_Util_String::replaceStar('123456789', -1, -2);
$this->assertEquals($actual, '1234567**'); $actual = App_Util_String::replaceStar('123456789', -4, -7);
$this->assertEquals($actual, '******789'); $actual = App_Util_String::replaceStar('123456789', -1, -3);
$this->assertEquals($actual, '123456***'); $actual = App_Util_String::replaceStar('123456789', -1);
$this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', -2);
$this->assertEquals($actual, '********9'); $actual = App_Util_String::replaceStar('123456789', -9);
$this->assertEquals($actual, '*23456789'); $actual = App_Util_String::replaceStar('123456789', -10);
$this->assertEquals($actual, '123456789'); $actual = App_Util_String::replaceStar('123456789', -10, -2);
$this->assertEquals($actual, '123456789');
}
上一篇:利用SVN工具下载OpenCore代码


下一篇:iOS之内存管理浅谈