php - regex to extract phone numbers from a string

Wednesday, November 4, 2015

i am having a small problem with my regex which i use to extract italian phone numbers from a string



<?php
$output = "+39 3331111111";
preg_match_all('/^((00|\+)39[\. ]??)??3\d{2}[\. ]??\d{6,7}$/',$output,$matches);
echo '<pre>';
print_r($matches[0]);
?>


it works correctly if the $output is just the telephone number but if i change the output with a more complex string like:



(eg. $output = "hello this is my number +39 3331111111 how are you?";)



it will not extract the number, how can i change my regex to extract the number?

0 comments:

Post a Comment