开发者

Easy Regex question

开发者 https://www.devze.com 2022-12-28 23:30 出处:网络
Trying to replace the first 12 digits of credit card numbers with X\'s in a predictable blob of text that contains the string:

Trying to replace the first 12 digits of credit card numbers with X's in a predictable blob of text that contains the string:

Credit Card Number: 1234123412341234

Here's my PHP function:

preg_replace('/Credit Card Number: ([0-9]{12})/','Cred开发者_开发问答it Card Number: XXXXXXXXXXXX',$str);

Help?


I don't see what's wrong. Perhaps you forgot to assign the result?

$str = preg_replace('/Credit Card Number: [0-9]{12}/','Credit Card Number: XXXXXXXXXXXX',$str);

Also, the capturing around ([0-9]{12}) is unnecessary if you don't need it.


Dumb question: you are assigning the returned value back to $str right?

$str = preg_replace('/(Credit Card Number: [0-9]{12}/','Credit Card Number: XXXXXXXXXXXX',$str);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号