I got it working when the number is separated with -. How can I add the parameters for when the numbers are like this:
(xxx) xxx xxxx
xxx.xxx.xxxx
xxx-xxx-xxxx
(xxx)xxx-xxxx
xxxxxxxxxx
xxx xxx xxxx
the php code:
//find phone in string
preg_match('/\b\d{3}\s*-\s*\d{3}\s*-\s*\d{4}\b/', $phone, $phone_matches);
$find_phone = $phone_matches[0];
EDIT: I found a way to replace it within the text. So I am still looking for all the formats to apply
$hide_phone = preg_replace('/\b\d{3}\s*-\s*\d{3}\s*-\s*\d{4}\b/', '[hidden phone]', $phone);
different approeach:
"/[(]*\d{3}[)]*\s*[.\-\s]*\d{3}[.\-\s]*\d{4}/"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With