Home >Backend Development >PHP Problem >How to hide bank card number in php
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.
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); }
[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!