duancai7002 2010-10-30 07:42
浏览 83
已采纳

如何模糊textarea字段中的数字

I have using cakephp and I want to obscure all numbers which is more than six digits.

something like this

 $string = "My id number is 77765444 in Sales dept.";

 becomes 

 $string = "My id number is XXXXXXXX in Sales dept." 

I appreciate any help.

Thanks.

  • 写回答

2条回答 默认 最新

  • dsnd7200 2010-10-30 07:47
    关注

    Try this using preg_replace_callback and an anonymous function:

    $string = preg_replace_callback('/\d{6,}/', function($match) { return str_repeat('X', strlen($match[0])); }, $string);
    

    The anonymous function is used to replace each occurrence of six or more consecutive digits by the same amount of X. If your PHP version does not support anonymous functions (available since 5.3), use a normal function instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突