Giter Site home page Giter Site logo

giggsey / libphonenumber-for-php Goto Github PK

View Code? Open in Web Editor NEW
4.7K 4.7K 464.0 15.72 MB

PHP version of Google's phone number handling library

Home Page: https://giggsey.com/libphonenumber/

License: Apache License 2.0

PHP 100.00%
hacktoberfest libphonenumber phone-number php

libphonenumber-for-php's People

Contributors

abhinavlal avatar ajayrungta avatar antonkomarev avatar benjaminhoegh avatar benmorel avatar boekkooi avatar cafferata avatar captn3m0 avatar davideme avatar ferk avatar garak avatar giggsey avatar icarussosie avatar igusev avatar joshuagiggxon avatar justjkk avatar midnightdesign avatar nephele avatar omahm avatar regius-cirruspath avatar samnela avatar sergeylukin avatar sergiy-petrov avatar simoheinonen avatar stollr avatar szepeviktor avatar thewilkybarkid avatar tom-1bg avatar wenzhengjiang avatar zoloft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libphonenumber-for-php's Issues

getNumberType problem..

Hi..

I got problem when calling getNumberType..

This is my script..

$number = "044 668 18 00";
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$number = $phoneUtil->parse($number, "CH");
$gType = $phoneUtil->getNumberType($number);
var_dump($gType);

above script just return int(0)

isValidNumber method for Argentine phone numbers is not working properly

Hi,
I'm using your library but I have some problems with Argentine phone number:
The next two numbers are valid but the library returns that are invalid.

0351-152-303-473
0351-152-389-491

I've used the online verision of google code library http://libphonenumber.appspot.com/ and it returns in both cases that they are valid

The code I've used is:

$numberStr = "0351-152-303-473";
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$numberProto = $phoneUtil->parse($numberStr, "AR");
$isValid = $phoneUtil->isValidNumber($numberProto);

$numberStr = "0351-152-389-491";
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$numberProto = $phoneUtil->parse($numberStr, "AR");
$isValid = $phoneUtil->isValidNumber($numberProto);

Thanks in advance!

Lluis

Loading via composer fails with "package not found"

It looks like the stock composer.json in README.md isn't complete enough or isn't correct.

I'm getting the following error when trying to load the library via composer:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package giggsey/libphonenumber-for-php ~6.0 could not be found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

I'm not sure what else needs to be added, but I'm guessing something is either wrong or missinge

getAsYouTypeFormatter missing

Hello !
I saw that the getAsYouTypeFormatter functionality is missing from your package. :(
It is present it the official Google library (v7.1.0).

Can you please implement it?

I am refering to this:
Formatting Phone Numbers 'as you type'

PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("US");
System.out.println(formatter.inputDigit('6')); // Outputs "6"
... // Input more digits
System.out.println(formatter.inputDigit('3')); // Now outputs "650 253"

How make early detection of invalid number?

isPossibleNumberWithReason returns true for number +420999999999. But isValidNumberForRegion returns false... I'm wondering how to detect invalid number during typing... If user enter "+420999" it should be marked as invalid.... how to do it ?

Thank you very much!

Remove dependency on ext-intl

This is a thought I've had for a few weeks now, but writing it down so progress can be tracked.

The Problem

The ext-intl dependency only exists because the Offline Geocoder needs to use Locale functions to get the country name.

This makes the library dependent on the version of libicu installed on the server, which could be out of date.

For instance, one of my Ubuntu (latest LTS release) machines returns different country names to the Travis boxes, so the unit tests do not pass on my local machine.

The Proposal

Introduce a new package that only contains the functions that the Offline Geocoder requires, and compile the latest data from CLDR. This would be a separate package from libphonenumber-for-php to allow the two to update independently.

Functions Required

Fatal Error on line 1462 of PhoneNumberUtil.php

Notice here $regionMetadata->getCountryCode(), there is no check to make sure that regionMetadata is an object, thus producing a fatal error.

        $normalizedNationalNumber .= $this->normalize($nationalNumber);
        if ($defaultRegion !== null) {
            $countryCode = $regionMetadata->getCountryCode();
            $phoneNumber->setCountryCode($countryCode);
        } else if ($keepRawInput) {
            $phoneNumber->clearCountryCodeSource();
        }
    }

The reason is on line 1414

$regionMetadata = $this->getMetadataForRegion($defaultRegion);

returns null if its not a valid region.

public function getMetadataForRegion($regionCode)
{
    if (!$this->isValidRegionCode($regionCode)) {
        return null;
    }

    if (!isset($this->regionToMetadataMap[$regionCode])) {
        // The regionCode here will be valid and won't be '001', so we don't need to worry about
        // what to pass in for the country calling code.
        $this->loadMetadataFromFile($this->currentFilePrefix, $regionCode, 0, $this->metadataLoader);
    }
    return isset($this->regionToMetadataMap[$regionCode]) ? $this->regionToMetadataMap[$regionCode] : null;
}

my suggestion is to test for null or throw an exception if the region code is not valid.

Speed up GeneratePhonePrefixData

Building the geo-data on my modest PC takes at least an hour.

This is a ridiculously long amount of time.

Low priority, just something to look at when time permits.

(If anyone else sees this, and fancies a crack, please give it a go and submit PR's).

ShortNumberInfo->isEmergencyNumber() fails if PhoneNumberUtil has not been initiated

$sortNumberUtil = \libphonenumber\ShortNumberInfo::getInstance();
$isEmergencyNumber = $sortNumberUtil->isEmergencyNumber('999', 'GB'); // false

// However...

\libphonenumber\PhoneNumberUtil::getInstance();
$sortNumberUtil = \libphonenumber\ShortNumberInfo::getInstance();
$isEmergencyNumber = $sortNumberUtil->isEmergencyNumber('999', 'GB'); // true

Pull request coming soon

Loading class

Hello guys. It's not a issue, it's a question, and sorry about this newbie question.

I tried load this class with no success. In the demo I saw "/vendor/autoload.php" and I didin't found it here. I think that have some way to do that and I don't know.

Can you guys help me with that? How can I include in my PHP script?

Thanks.

form default_region

Hi there,

I have a form and I wonder how(if it's possible) can I get the country code corresponding to the given phone number? Because today a belgian guy filled my form with his belgian mobile phone number and it seemed that belgian mobile phones and french fixed lines are alike. I know that in this case it would be hard to get the right country code but before today, only french guys filled my form and soon it will be belgian and swiss people that will fill my form and maybe others in the future, so, Can I get the country code to the given number and How?

Thank you guys!

phing compile (build.php fails to find /../vendor/autoload.php.

Running phing inside /lib/3rd/vendor/giggsey/libphonenumber-for-php/ results in a fail to require with build.php.

Buildfile: /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build.xml

libphonenumber-for-php > delete-test-carrierdata:

[delete] Deleting directory /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/carrier/data
[mkdir] Created dir: /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/carrier/data

libphonenumber-for-php > delete-test-prefixmapper:

[delete] Deleting directory /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/prefixmapper/data
[mkdir] Created dir: /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/prefixmapper/data

libphonenumber-for-php > delete-test-coredata:

[delete] Deleting directory /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/core/data
[mkdir] Created dir: /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/core/data

libphonenumber-for-php > delete-test-timezone:

[delete] Deleting directory /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/timezone/data
[mkdir] Created dir: /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/Tests/libphonenumber/Tests/timezone/data

libphonenumber-for-php > cleanup-test-data:

libphonenumber-for-php > svn-checkout:

Checked out revision 712.

libphonenumber-for-php > build-test-metadata:

PHP Warning: require(/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php): failed to open stream: No such file or directory in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4
PHP Fatal error: require(): Failed opening required '/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4

libphonenumber-for-php > build-geo-test-data:

PHP Warning: require(/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php): failed to open stream: No such file or directory in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4
PHP Fatal error: require(): Failed opening required '/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4

libphonenumber-for-php > build-carrier-test-data:

PHP Warning: require(/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php): failed to open stream: No such file or directory in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4
PHP Fatal error: require(): Failed opening required '/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4

libphonenumber-for-php > build-timezones-test-data:

PHP Warning: require(/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php): failed to open stream: No such file or directory in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4
PHP Fatal error: require(): Failed opening required '/{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/../vendor/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 4

libphonenumber-for-php > compile-test-data:

libphonenumber-for-php > test:

sh: vendor/bin/phpunit: No such file or directory

BUILD FINISHED

Total time: 1.4527 second

I tried modifying build.php to include the vender/autoload.php but that just resulted in:

PHP Fatal error: Class 'libphonenumber\buildtools\BuildApplication' not found in /{redacted}/lib/3rd/vendor/giggsey/libphonenumber-for-php/build/build.php on line 6

Missing changes from LPN 5.9

Good day,

I'm using your library and also I'm using the JavaScript version provided by Google.

After updating to the latest version that you provided based on the Google 5.9 update, I came across a "KW" phone number that validates in Google's Java and Javascript code but fails in the PHP implementation.

After reviewing both codes, I noticed a missing line between the 2 regex codes.

5.9 version uses this pattern:

'NationalNumberPattern' => '
(?:
5(?:
1[0-5]|
[05]\d
)|
5(?:
5[015-9]
)|
6(?:
0[034679]|
5[015-9]|
6\d|
7[067]|
9[0369]
)|
9(?:
0[09]|
4[049]|
6[069]|
[79]\d|
8[08]
)
)\d{5}
',

while the lib code is missing the pattern which I added later
5(?:
5[015-9]
)|

Anyways, I figured that I let you know about it,

and in appreciation to your efforts, if you need any help, please consider my request to become one of the contributors.

regards

Generate international number with country code, not name

Hi there

I'm trying to work out how to get an international number using the country code instead of the country name - e.g. '44' instead of 'GB'. Obviously the simple format is '+'.$countryCode+phoneNumber, but seeing as only some countries drop the preceding zero, a simple rule like that wouldn't work (I don't think).

$countryCode = '44';
$phone = '01234567899';
$internationalNumber = '+441234567899';

Is there a way to do this with this library? essentially I just want to send '44' to the parse() function instead of 'GB';

Thanks!

[Feedback wanted] PhoneNumber->__toString() gives misleading data

The current version of the PHP returns +[Country Code][National Number].

However, this is misleading, as it looks like it's E164. However, for some regions/types of number, this is not valid. For example, the example number of Italy is +390212345678, but if you parse this number, then do a __toString() on it, it'll actually return +39212345678 (note the missing 0 after the country code).

The Java version of the project does the following:

    public String toString() {
      StringBuilder outputString = new StringBuilder();
      outputString.append("Country Code: ").append(countryCode_);
      outputString.append(" National Number: ").append(nationalNumber_);
      if (hasItalianLeadingZero() && isItalianLeadingZero()) {
        outputString.append(" Leading Zero(s): true");
      }
      if (hasNumberOfLeadingZeros()) {
        outputString.append(" Number of leading zeros: ").append(numberOfLeadingZeros_);
      }
      if (hasExtension()) {
        outputString.append(" Extension: ").append(extension_);
      }
      if (hasCountryCodeSource()) {
        outputString.append(" Country Code Source: ").append(countryCodeSource_);
      }
      if (hasPreferredDomesticCarrierCode()) {
        outputString.append(" Preferred Domestic Carrier Code: ").
            append(preferredDomesticCarrierCode_);
      }
      return outputString.toString();
    }

For the example Italian number, this causes the output to be:

Country Code: 39 National Number: 212345678 Leading Zero(s): true

My question to people who see this is: Should we change the string output to match what the Java version has. The issue has been present since 6fec96d.

Tests fail on HHVM

From memory, this is an issue with the Regex used.

Need to write a simple testable script with a failing number

Possible bug while validating a phone from Colombia

Hi,

while trying to parse a phone number from Colombia, I've seen that the lib returns that this phone is valid: 573133333333
(57 is the country code for CO)

http://giggsey.com/libphonenumber/?phonenumber=573133333333&country=CO&language=&region=

But when trying to parse this number: 00573133333333 (this is the same number returned by the API for calling from GB) the method isValidNumber returns false.

http://giggsey.com/libphonenumber/?phonenumber=00573133333333&country=CO&language=&region=

This does not happens when validating other countries, which accepts the full country code, so I could think this is a possible issue.

Thanks,
Oriol

The problem with the Chinese phone numbers.

Hello everybody. I get some problems with en/86.php. This file is too big compare with others (4,8Mb).
So, I must spend big amount of valuable memory (almost 75Mb) when use geocoding for Chinese phone numbers. When I add necessary size of memory by ini_set (although it is not good) I anyway get problems with geocoding some numbers. For example I try use geocoding for 86-157-9662-1289.
Actualy there is no such number and I should get empty result, instead I get fatal error, because it is need even more memory. Why that, I don't no. Anybody knows how to resolve this problem with memory wasting? May be should split the file 86.php into smaller files. Please, help me.

Mobile type format for MD region

version
"giggsey/libphonenumber-for-php":"7.0.2"

http://giggsey.com/libphonenumber/?phonenumber=%2B373+68+111+111&country=MD&language=&region=MD
show (it's mobile type)
+373 681 11 111

must be formatted as: +373 68 111 111

For local (landline) phonenumber - all good
http://giggsey.com/libphonenumber/?phonenumber=%2B373%2022%20111%20111&country=MD&language=&region=MD

you can see formats in wiki
https://en.wikipedia.org/wiki/Telephone_numbers_in_Moldova

0-xx-xx-xx-xx call between localities and mobile phone companies
+373-xx-xx-xx-xx call to Moldova from abroad

similar discussion https://github.com/googlei18n/libphonenumber/issues/632

Doesn't accept a fixed Line Indian number

The landline number of Guwahati, India was updated to 8 digits from 7 by prepending a 2 since 2002. This change is not reflected in the Indian phone metadata file.
The number is 0361-22300102, which is show as false.
Please update the regex to match this pattern.

Ref: See section "9-10 November 2002 - Assam area changes" in http://www.wtng.info/wtng-91-in.html for more details.

International with leading zero

Is it possible to display a number with a leading zero? So similar to international, but with with (0) added.

+31 123 456 789 --> +31 (0) 123 456 789

Demo code

Please consider releasing the full code used on http://giggsey.com/libphonenumber/ to illustrate an end-to-end demo. Also please mention use of composer, as this isn't immediately obvious to everyone.

Excellent work on the lib though, it works like a charm!

New Phone numbers are not giving proper results

I am using this API and have downloaded the whole project through composer.
So whenever the any git file is updated would i'll be notified ?
If not, how would i'll updating my API with the new number series.

Some numbers are returned with scientific E notation

Some numbers are converted to a float with E notation, e.g.

$num = $phoneUtil->parse('0358112345678987', 'DE');
echo $phoneUtil->format($num, \libphonenumber\PhoneNumberFormat::E164);
// output:
'+493.5811234567899E+14'

I noticed a cast to float in PhoneNumberUtil.php. If it is removed, the correctly formatted number is returned.

--- PhoneNumberUtil.php.orig    2014-03-12 22:43:02.000000000 +0100
+++ PhoneNumberUtil.php 2014-03-12 22:43:50.000000000 +0100
@@ -1403,7 +1403,7 @@
                 "The string supplied is too long to be a phone number.");
         }
         $this->setItalianLeadingZerosForPhoneNumber($normalizedNationalNumber, $phoneNumber);
-        $phoneNumber->setNationalNumber((float)$normalizedNationalNumber);
+        $phoneNumber->setNationalNumber($normalizedNationalNumber);
     }

     /**

validate Chinese mobile number fail

Hi~
When i use this library to validate this number "18612249027ab" with region "CN". It seems that this number is a valid mobile number.But exactly it is a wrong mobile number, Chinese mobile does't contain letters.

ps: I am so sorry about my poor english : )

Best regards
Thanks very much

Build failed: You must specify readable directory as repository.

vendor/giggsey/libphonenumber-for-php/build.xml:98:33: You must specify readable directory as repository.

vendor/giggsey/libphonenumber-for-php/vendor/phing/phing/classes/phing/tasks/ext/git/GitFetchTask.php(111): GitBaseTask->getGitClient(false, 'libphonenumber-...')

Happens when I try to run vendor/bin/phing compile.

PhoneNumberUtil::parseAndKeepRawInput doesn't behave like the JS version

Hi,

First thank you for this nice port from the original JS library to PHP.

A great thing in the original version was the ability to process a phone number without knowing the region. I'm quite new to the PHP version, but as far as I understood, it aims at reproducing the behavior of JS version.
In the JS version (demo here), PhoneNumberUtil.parseAndKeepRawInput(phoneNumber, regionCode) can be invoked with a missing/empty regionCode. In this PHP port, it terminates with an exception "Missing or invalid default region".

I browsed the code a bit and found that PhoneNumberUtil::parseAndKeepRawInput() calls PhoneNumberUtil::parseHelper() with $checkRegion parameter set to true (line 1330). Changing this to false fixes the exception, but then the library still isn't able to process the number. For instance, +33655442211 is properly identified as French mobile number by the JS version, but not processed by the PHP version.

I assume it's something not yet implemented, but just in case it's a bug I thought I'd post about it here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.