I can provide actual website and info if needed.. I am pulling a "text" out of mysql with php. Within this text is a formatted phone number formatted 123-456-7890 what i want to do is make it have all the text in tact but graph that bit and change it to 123-456-XXXX and hide the phone number. Anyone???
function mask_num($number) { return preg_replace('/\d{4}$/', 'XXXX', $number); } PHP: $number = mask_num($number); PHP:
Awesome thanks, this works. Well most of the time. Could you explain to me how it works so I can figure out why sometimes it only catches one of the phone numbers and why sometimes it doesn't catch it at all? I know the code mostly it's just this '/\d{4}$/' i'm not sure exactly what it all means. edit ** just to be clear when a phone number has a , or . after it then it doesn't mask. also when there are two sets of phone numbers it's only masks one set.
Can you post an example of the whole text that is pulled from the database? And also all possible number formats.
This should be fine: preg_replace('/(\d{3}-\d{3}-)\d{4}/', '$1XXXX', $number); PHP: Or maybe even this: preg_replace('/\d{4}/', 'XXXX', $number); PHP: Depends on how much other data is in the text.
thanks to both of you preg_replace('/(\d{3}-\d{3}-)\d{4}/', '$1XXXX', $number); seems to of done it PHP: