PHP code example of tonglil / localize

1. Go to this page and download the library: Download tonglil/localize library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tonglil / localize example snippets




use Localize\Localize;

// Create a new localize instance.
$localize = new Localize();
// Set the locale using a two digit ISO country code.
$localize->setLocale('CA');

$address = [
    'address'       => '525 Seymour Street',
    'city'          => 'Vancouver',
    'region'        => $localize->region('british columbia', true),
    'postal_code'   => $localize->postalCode('v6b3h7'),
    'country'       => $localize->country('CANADA', false),
    'phone'         => $localize->phone('5555555555'),
];

echo $address['region'];        // BC
echo $address['postal_code'];   // V6B 3H7
echo $address['country'];       // Canada
echo $address['phone'];         // 555-555-5555

// Region and country both accept a second parameter that formats the value to
// its short version when true, otherwise uses the long version by default.
echo $localize->region('ontario', true);    // ON
echo $localize->region('ontario', false);   // Ontario

// Postal code and phone number will attempt to massage a limit amount of
// formatting into the standard output.
echo $localize->phone('555 555-5555');                  // 555-555-5555 regional "de-facto" formatting
echo $localize->phoneE164('+1 555 555-5555');           // 011-1-555-555-5555 full E.164 formatting
echo $localize->phoneE164('+1 555 555-5555', false);    // +1-555-555-5555 common E.164 formatting
echo $localize->postalCode('V6b 3h7');                  // V6B 3H7

// Basic validation is performed; if a match is not found and can not be
// massaged to a format, null is returned.
var_dump($localize->phone('abc-def-gehi')); // null