How to hide bank card number in php

藏色散人
Release: 2023-03-08 09:44:01
Original
4523 people have browsed it

php method to hide bank card numbers: first create a PHP sample file; then define a formatBankCardNo method; finally, in the method body, replace the middle digits of the bank card number with asterisks through functions such as "str_split" and "array_fill" That’s it.

How to hide bank card number in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

During development, I often encounter some small problems. For example, user privacy issues deserve attention, and all content displayed on the page must be processed

It is also common to mask bank cards, mobile phone numbers, real names, and ID cards

  /** 
* 对银行卡号进行掩码处理 
* 掩码规则头4位,末尾余数位不变,中间4的整数倍字符用星号替换,并且用每隔4位空格隔开 
* @author 晓风<215628355@qq.com> 
* @param  string $bankCardNo 银行卡号 
* @return string             掩码后的银行卡号 
*/  
function formatBankCardNo($bankCardNo){  
//每隔4位分割为数组  
$split = str_split($bankCardNo,4);  
//头和尾保留,其他部分替换为星号  
$split = array_fill(1,count($split) - 2,"****") + $split;  
ksort($split);  
//合并  
return implode(" ",$split);  
}
Copy after login

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to hide bank card number in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template