1. Go to this page and download the library: Download digitalrevolution/intl 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/ */
digitalrevolution / intl example snippets
use DR\Internationalization\Currency\CurrencyFormatOptions;
use DR\Internationalization\Number\NumberFormatOptions;
use DR\Internationalization\NumberFormatService;
use Money\Money;
// set default configuration
$currencyOptions = (new CurrencyFormatOptions())
->setLocale('nl_NL')
->setCurrencyCode('EUR')
->setGrouping(false);
$numberOptions = (new NumberFormatOptions())
->setLocale('nl_NL')
->setDecimals(2)
->setTrimDecimals(true);
$service = new NumberFormatService($currencyOptions, $numberOptions);
$service->currency(1500.5);
// output: € 1500,50
$service->currency(new Money('150050', new Currency('EUR')));
// output: € 1500,50
$service->currency(1500.5, (new CurrencyFormatOptions())->setGrouping(true));
// output: € 1.500,50
$service->number(1500.5);
// output: 1500,50
$service->number(1500.5, (new NumberFormatOptions())->setGrouping(true));
// output: 1.500,50
$service->number(1500.0, (new NumberFormatOptions())->setTrimDecimals(NumberFormatOptions::TRIM_DECIMAL_ALL_OR_NOTHING));
// output: 1500
$service->number(1500.5, (new NumberFormatOptions())->setTrimDecimals(NumberFormatOptions::TRIM_DECIMAL_ALL_OR_NOTHING));
// output: 1500.50
$service->number(1500.5, (new NumberFormatOptions())->setTrimDecimals(NumberFormatOptions::TRIM_DECIMAL_ANY));
// output: 1500.5
$dateFormatOptions = new DateFormatOptions('nl_NL', date_default_timezone_get())
$dateFormatter = new DateFormatService($dateFormatOptions);
$dateFormatter->format(time(), 'eeee dd LLLL Y - HH:mm:ss');
// example output: zaterdag 02 juni 2040 - 05:57:02
$dateFormatter->format('next saturday', 'eeee dd LLLL Y - HH:mm:ss');
// example output: zaterdag 02 juni 2040 - 05:57:02
$dateFormatter->format(new DateTime(), 'eeee dd LLLL Y - HH:mm:ss');
// example output: zaterdag 02 juni 2040 - 05:57:02
$dateFormatOptions = new DateFormatOptions('nl_NL', date_default_timezone_get())
$dateFormatter = new DateFormatService($dateFormatOptions);
$dateFormatter->formatRelative(time(), 'Y-m-d', new RelativeDateFormatOptions(1));
// example output: Vandaag
$dateFormatter->formatRelative(new DateTime('+1 day'), 'Y-m-d', new RelativeDateFormatOptions(1);
// example output: Morgen
$dateFormatter->formatRelative(new DateTime('+2 days'), 'Y-m-d', new RelativeDateFormatOptions(2));
// example output: Overmorgen
$dateFormatter->formatRelative(new DateTime('-2 days'), 'Y-m-d', new RelativeDateFormatOptions(2));
// example output: Eergisteren
// This will not convert the date to a relative date, as the options limit it one day ahead. Instead, it formats the date to the given pattern.
$dateFormatter->formatRelative(new DateTime('+2 days'), 'Y-m-d', new RelativeDateFormatOptions(1));
// example output: 2024-01-03
use DR\Internationalization\PhoneNumber\PhoneNumberFormatOptions;
use DR\Internationalization\PhoneNumberFormatService;
// set default configuration
$phoneNumberOptions = (new PhoneNumberFormatOptions())
->setDefaultCountryCode('NL')
->setFormat(PhoneNumberFormatOptions::FORMAT_INTERNATIONAL_DIAL);
$service = new PhoneNumberFormatService($phoneNumberOptions);
$service->format("+31612345678");
// output: 0031612345678
$service->format("0612345678");
// output: 0031612345678
use DR\Internationalization\PhoneNumberParseService;
$parseService = new PhoneNumberParseService("NL");
$parsedPhoneNumber = $parseService->parse("+31612345678");
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.