giggsey / libphonenumber-for-php

PHP version of Google's phone number handling library
https://giggsey.com/libphonenumber/
Apache License 2.0
4.78k stars 468 forks source link

can I use this to determine whether a large blob of text contains any valid phone number? #369

Closed vesper8 closed 4 years ago

vesper8 commented 4 years ago

This is what I'm looking for, I have large swats of random text (user messages) and I want to detect if any of them contain valid phone numbers.. the numbers come an assortment of formats and countries

giggsey commented 4 years ago

Give https://github.com/giggsey/libphonenumber-for-php/blob/master/docs/PhoneNumberMatcher.md a try

vesper8 commented 4 years ago

thanks for the quick reply. I'm giving this a try and the first problem I see is that the region argument is not optional. You have to pass a region code but I don't know what that code should be, I guess I could iterate over every possible region code trying to find a match but that would be too expensive.

Also, once you do get a match, there doesn't seem to be a way to verify that? Like you can loop

        foreach($phoneNumberMatcher as $match) {
            dd($match);
        }

But there is no way to do something like

if(count($phoneNumberMatcher->matches())) {} 
or
$phoneNumberMatcher->hasMatches()

In my case, I am not interested in the actual numbers and their details, rather I want to know if the text contains anything that looks like a phone number

Any idea on how I could achieve this with this library?

giggsey commented 4 years ago

Did you try just count($phoneNumberMatcher)?

giggsey commented 4 years ago

Closing due to inactivity.

If you have any further questions, feel free to re-open the issue.