1
我已經使用cakephp,並且想要隱藏超過六位數字的所有數字。如何掩蓋textarea字段中的數字
像這樣
$string = "My id number is 77765444 in Sales dept.";
becomes
$string = "My id number is XXXXXXXX in Sales dept."
我感謝所有幫助。
謝謝。
我已經使用cakephp,並且想要隱藏超過六位數字的所有數字。如何掩蓋textarea字段中的數字
像這樣
$string = "My id number is 77765444 in Sales dept.";
becomes
$string = "My id number is XXXXXXXX in Sales dept."
我感謝所有幫助。
謝謝。
嘗試此使用preg_replace_callback
和anonymous function:
$string = preg_replace_callback('/\d{6,}/', function($match) { return str_repeat('X', strlen($match[0])); }, $string);
匿名功能用於以相同的量的X
取代的六個或更多個連續的數字每次出現。如果您的PHP版本不支持匿名函數(自5.3開始可用),請改用普通函數。
$string = preg_replace('/\d/', 'X', "My id number is 77765444 in Sales dept.");
不,這隻會將所有數字轉換爲X,這不是OP所要求的。 – 2010-10-30 08:00:28
你的意思是1)如果該數字不超過6位數字,2)如果數字出現多次,例如''出於某種原因,銷售部門有2個ID號碼77765444「 – 2010-10-30 09:25:39