掩盖信用卡和银行账户信息
我正在寻找一个可以屏蔽信用卡和信用卡的 php 函数。银行信息,例如路由号码和帐号。我需要屏蔽多种格式,因此现有的堆栈溢出答案对我帮助不大。
例如,如果输入为 304-443-2456
,则该函数应返回 xxx-xxx-2456
。 有时该数字带有破折号,并且可以有不同的长度。
我正在寻找一些通用的东西,我可以根据需要扩展它,最好是 zend 框架视图帮助程序类。
I'm looking for a php function which can mask credit card & bank information such as routing number and account numbers. I need to mask many formats, so the existing stack overflow answers don't help me that much.
So for example, if the input is 304-443-2456
, the function should return xxx-xxx-2456
.
Sometimes the number has dashes, and can be in various lengths.
I'm looking for something generic, that I can extend as needed, preferably a zend framework view helper class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一些小的正则表达式在它自己的函数中,可用配置:
如果函数失败,它将返回所有屏蔽的(例如不同的分隔符,少于4位数字等)。您可以说内置了一些儿童安全措施。
演示
Some little regex in a function of it own, configuration available:
If the function fails, it will return all masked (e.g. a different seperator, less than 4 digits etc.). Some child-safety build in you could say.
Demo
输出:
Outputs:
我为此使用了一个视图助手。我倾向于避免使用正则表达式,因为我总是需要很长时间才能弄清楚它的作用,特别是当我在一段时间后回到代码时。
在你看来
I use a view helper for that. I tend to avoid Regex though as it always takes me ages to work out what it does, especially if I come back to code after a while.
In your view
查看此问题的一个好方法是查看哪些内容不会被屏蔽,并为其他所有内容输出 xs。一个简单、廉价的解决方案是:
如果不需要维护连字符和特殊字符,速度会更快
A good way to look at this is at what won't be masked and outputing xs for everything else. A simple, inexpensive solution is:
Would be even faster if there was no need to maintain the hyphens and special characters