2017 © Pedro PelĆ”ez
 

library geo

Geographical data helpers

image

datingvip/geo

Geographical data helpers

  • Tuesday, April 17, 2018
  • by kornrunner
  • Repository
  • 13 Watchers
  • 1 Stars
  • 1,726 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 9 % Grown

The README.md

geo

Geographical data helpers, (*1)

ISO / FIPS code conversions

Convert FIPS 10-4 to ISO 3166-1 code, or vice versa:, (*2)

require_once 'vendor/autoload.php';

use DatingVIP\geo\Country_Code;

echo (new Country_Code)->fips2iso ('SG');
// outputs: SN

echo (new Country_Code)->iso2fips ('PR');
// outputs: RQ

Postal Code Validation

Validate or parse Postal Codes for almost any country (using regular expressions). Country codes are accepted in ISO 3166-1 format., (*3)

require_once 'vendor/autoload.php';

use DatingVIP\geo\Postal_Code;
use DatingVIP\geo\Validation_Exception;

$postal_code = new Postal_Code ();

// check if country is covered
var_dump ($postal_code->coveringCountry ('SG'));
// bool(true)

// get an array of human readable postal code formats for given country
var_dump ($postal_code->getFormats ('RS'));
// array(1) {
//  [0]=>
//  string(5) "#####"
//}

// check if zip code is valid
var_dump ($postal_code->isValid ('RS', '11000'));
// bool(true)

try {
    $postal_code->isValid ('WW', '....');
} catch (Validation_Exception $e) {
    var_dump ($e->getMessage());
    // string(26) "Invalid country code: "WW""
}

if ($postal_code->contains ('RS', '11000, Beograd'))
{
    var_dump ($postal_code->capture ('RS', '11000, Beograd'));
    // string(5) "11000"
}

Map of wildcards to regexes: + # = 0-9 + @ = a-zA-Z + * = a-zA-Z0-9, (*4)

State Codes

ISO 3166-2 principal subdivisions (provinces, states, regions) utility class, (*5)

require_once 'vendor/autoload.php';

use DatingVIP\geo\State_Code;

$state_code = new State_Code ();

// get available states/regions in given country
var_dump ($state_code->getCountry ('CY'));
//array(6) {
//  ["04"]=>
//  string(12) "Ammóchostos"
//  ["06"]=>
//  string(9) "Kerýneia"
//  ["03"]=>
//  string(8) "LƔrnaka"
//  ["01"]=>
//  string(9) "LefkosĆ­a"
//  ["02"]=>
//  string(8) "Lemesós"
//  ["05"]=>
//  string(6) "PƔfos"
//}

// get region/state name based on given code
var_dump ($state_code->getName ('CY', '02'));
//string(8) "Lemesós"

// get region/state code based on given name
var_dump ($state_code->get ('US', 'Alabama'));
//string(2) "AL"

// check if given country / state code combo is valid
var_dump ($state_code->isValid ('AB', 'CD'));
//bool(false)

// check if given country / state code combo is valid
var_dump ($state_code->isValid ('RS', '03'));
//bool(true)

The Versions

17/04 2018

dev-master

9999999-dev https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3 LGPL-3.0-or-later

The Requires

  • php >=5.4.0

 

validation geo postal code iso 3166-1 iso 3166-2 fips 10-4

17/04 2018

v1.0.10

1.0.10.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPL-3.0-or-later

The Requires

  • php >=5.4.0

 

validation geo postal code iso 3166-1 iso 3166-2 fips 10-4

16/04 2018

v1.0.9

1.0.9.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPL-3.0-or-later

The Requires

  • php >=5.4.0

 

validation geo postal code iso 3166-1 iso 3166-2 fips 10-4

10/12 2014

v1.0.8

1.0.8.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

validation geo postal code iso 3166-1 iso 3166-2 fips 10-4

10/12 2014

v1.0.7

1.0.7.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

validation geo postal code iso 3166-1 iso 3166-2 fips 10-4

28/04 2014

v1.0.5

1.0.5.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

validation geo postal code iso 3166-1 iso 3166-2 fips 10-4

25/04 2014

v1.0.4

1.0.4.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

validation geo postal code

25/04 2014

v1.0.3

1.0.3.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

validation geo postal code

11/04 2014

v1.0.2

1.0.2.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

geo

11/04 2014

v1.0.1

1.0.1.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

geo

11/04 2014

v1.0.0

1.0.0.0 https://github.com/DatingVIP/geo

Geographical data helpers

  Sources   Download

LGPLv3

The Requires

  • php >=5.4.0

 

geo