PHP在字符串中查找包含所有可能组合的电话号码

PHP在字符串中查找包含所有可能组合的电话号码,php,Php,我让它工作时,数字是分开的-。当数字如下所示时,如何添加参数: (xxx) xxx xxxx xxx.xxx.xxxx xxx-xxx-xxxx (xxx)xxx-xxxx xxxxxxxxxx xxx xxx xxxx php代码: //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];

我让它工作时,数字是分开的-。当数字如下所示时,如何添加参数:

(xxx) xxx xxxx
xxx.xxx.xxxx
xxx-xxx-xxxx
(xxx)xxx-xxxx
xxxxxxxxxx
xxx xxx xxxx
php代码:

//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];
编辑: 我找到了在文本中替换它的方法。因此,我仍在寻找所有适用的格式

$hide_phone = preg_replace('/\b\d{3}\s*-\s*\d{3}\s*-\s*\d{4}\b/', '[hidden phone]', $phone);
试用

preg_match('\(?[2-9][0-8][0-9]\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}',$phone, $phone_matches);
不同的批准:

"/[(]*\d{3}[)]*\s*[.\-\s]*\d{3}[.\-\s]*\d{4}/"

您的
*
应该是
或更新正则表达式,因为有效的电话号码可以是
((800.-234--4214