In PHP I'm searching for phonenumbers in a certain text.
I use explode()
to divide the text in different parts,using the area code of the city I'm searching for as the delimiter. The problem is that phonenumbers that include the same numbers as the area-code are not returned well.
For example:
"foofoo 010-1234567 barbar"
splits into "foofoo "
and "-1234567 barbar"
but
"foofoo 010-1230107 barbar"
splits into "foofoo "
, "-123"
and "7 barbar"
!
I can use the first one to reconstruct the phonenummer with the areacode, but the second goes wrong of course...
I guess I need a regular expression to split the text with some kind of mechanism to not split on short strings, instead of explode()
, but I don't know how to do it.
Any ideas or a better way to search for phonenumbers in a text ?
UPDATE: The format is NOT consistent, so looking for the hyphen is no solution. Some phone numbers have spaces between the area code and number, some have hooks, some have nothing, etc. Dutch phonenumbers have an areacode of 2,3 or 4 numbers and are usually 10 numbers in total.