I need to parse phone numbers in strings, each string could have more than one number. My problem is that phone number could appear like this:
912343267
91 234 32 67
912 343 267
34912343267
+34912343267
0034912343267
+34 912343267
+34 91 234 32 67
+34 912 343 267
How can I possible deal with this? If you have some clue, would be appreciated.
Best Regards,
Updade1:
I'm testing the code like in the real environment:
$phone_list = "912343267 91 fgf ddf 234 32 67 dfffgg g 912 343 267 ffd dff fff 34912343267 ddssf f +34912343267 f fdd d 0034912343267 derd df e +34 912343267 fdd ff +34 91 234 32 67 ffd vv ff f +34 912 343 267";
$string = preg_replace('~[^0-9]~','',$phone_list);
echo $string;
Gives me:
91234326791234326791234326734912343267349123432670034912343267349123432673491234326734912343267
It is possible to output the numbers in an array?
Best Regards,
Update2:
I have tested with another kind of string but fails. I will post the example if someone have any clues on this.
$phone_list = '</div>A Front para<br /><br /><br /><br /><br /><br />-Apoio;<br />-Criação;<br />-Campanhas;<br />-Promoções<br /><br /><br />CONDIÇÕES:<br /><br />Local de Trabalho: Es<br />Folgas: Mistas<br /><br /><br /><br />ordem 500€<br /><br /><br /><br />Mínimos:<br /><br />- Conhecimentos;<br />- Ensino ;<br />-INGLÊS.<br /><br /><br /><br />Candidaturas: <br />[email protected]<br />218559372 | 927 555 929 | <br />RH<br />Rua C. Sal. 40<br />1000-000 Lisboa<br /><br /><br />';
$phone_list = preg_replace('~[^0-9a-z]~i','',$phone_list);
$phone_list = preg_split('~[a-z]+~i',$phone_list);
print_r($phone_list);
The code return:
Array ( [0] => [1] => 500 [2] => 218559372927555929 [3] => 40 [4] => 1000000 [5] => )
The code should parse: 218559372 and 927555929 as separate numbers.
Any clues on this?
Best Regards,