我正在尝试验证04或+61开头的电话号码。我从数据库中获取电话号码,然后用于每个循环,遍历每个电话号码并使用preg_grep进行验证。当我只输入一个电话号码时,它可以正常工作。但是当我使用变量(数组)时,它不会显示任何结果。
$records[] = $row;
$PhoneHome = $row['Phonehome'];
//print_r($PhoneHome);
$phoneNumberValidate = "/^(?:\+?61|0)4 ?(?:(?:[01] ?[0-9]|2 ?[0-57-9]|3 ?[1-9]|4 ?[7-9]|5 ?[018]) ?[0-9]|3 ?0 ?[0-5])(?: ?[0-9]){5}/";
foreach ($records as $r ){
if(preg_grep($phoneNumberValidate,$PhoneHome,$matches))
{
print_r($matches);
}
}
答案 0 :(得分:0)
$ PhoneHome [] = $ row [(Phonehome'];
print_r($ PhoneHome)
foreach($ records为$ row)
{
$ phoneNumberValidate =“ / ^(?:+?61 | 0)4?(?:(?:[01]?[0-9] | 2?[0-57-9] | 3?[1 -9] | 4?[7-9] | 5?[018])?[0-9] | 3?0?[0-5])(?:?[0-9]){5} /“ ;
if(preg_match_all($ phoneNumberValidate,$ row [Phonehome'],$ matches))
{ print_r($ matches)
}
}