preg_match_all('/(Moscow|St. Petersburg|Regions:)\s*([\+\-\d\(\)\s]+)/m', $textt, $r);
$resultphone = array_unique($r);
$phone = array(); // array for the phone
foreach ($resultphone[0] as $v) { // iterate through phones to fill the array
$vv = trim($v);
// echo($v.'<br>'); // for output
$phone[] = $vv;// for recording
}
//remove duplicate
$resultphone = array_unique($phone);
foreach($resultphone as $value) // write a good array
{
echo $value. "\n";
$str2.= "\n". $value; //"\n".
}
var_dump($str2);
/home/ubuntu/workspace/gm3.php:117:
string(421) "
Array
Moscow: +7 (495) 565-38-71
Saint-Petersburg: +7 (812) 385-57-81
Regions: +7 (8362) 32-85-45
Moscow:
Saint Petersburg:
Regions:
Moscow: +7 (495) 565-38-71
Saint-Petersburg: +7 (812) 385-57-81
Regions: +7 (8362) 32-85-45
Moscow: +7 (495) 565-38-71
Saint-Petersburg: +7 (812) 385-57-81
Regions: +7 (8362) 32-85-45"
Find more questions by tags PHP
But at the expense ranges in regexps did not understand what was meant! - Kamron29 commented on July 8th 19 at 16:46
Something like this:
preg_match_all("#(\w+):\s*([\+\-\d\(\)\s]+)#siu", $testStr, $resultphone);
If phones are not only "Moscow", "Saint Petersburg" and "Regions" - Nash_Marv commented on July 8th 19 at 16:49