PHP code example of codewiser / intl

1. Go to this page and download the library: Download codewiser/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/ */

    

codewiser / intl example snippets


config('app.timezone', 'UTC'),
config('app.currency', 'EUR'),
config('app.calendar', \IntlDateFormatter::GREGORIAN),
config('app.transliterator', Transliterator::ANY_LATIN)

use Codewiser\Intl\IntlManager;
use Codewiser\Intl\Intl\Transliterator;

/**
 * Register any application services.
 */
public function register(): void
{
    $this->app->extend(IntlManager::class, fn (IntlManager $intl) => $intl
        ->useCurrency('EUR')
        ->useCalendar(\IntlDateFormatter::GREGORIAN)
        ->useTransliterator(Transliterator::ANY_LATIN)
    );
}

intl()->date($date)->format(
    date: \IntlDateFormatter::FULL,
    time: \IntlDateFormatter::SHORT
);
// Saturday, April 12, 1952 at 3:30 PM

intl()->date($date)->format(date: \IntlDateFormatter::SHORT);
// 4/12/52

intl()->date($date)->format(time: \IntlDateFormatter::FULL);
// 3:30:42 PM Coordinated Universal Time

intl()->date($date)->short();
// 4/12/52 3:30 PM

intl()->date($date)->full();
// Saturday, April 12, 1952 at 3:30:42 PM Coordinated Universal Time

// etc.

intl()->date($date)->skeleton('yMMMEd');
// Sat, Oct 3, 2026

intl()->date($date)->skeleton('yQQQ');
// Q4 2026

intl()->date($date)->skeleton('Hm');
// 15:04

$period = now()->toPeriod(now()->addHour());

intl()
    ->period($period)
    ->format(\IntlDateFormatter::LONG, \IntlDateFormatter::LONG);
// April 12, 1952 from 3:30:42 PM UTC to 4:30:42 PM UTC

// Shortcuts:

// Use default app currency
intl()->number(1234.56)->currency();      // €1,234.56

// Override default currency
intl()->number(1234.56)->currency('USD'); // $1,234.56

intl()->number(1234.56)->decimal();       // 1,234.56
intl()->number(0.564)->percent();         // 56.4%
intl()->number(1234.56)->spellout();      // one thousand two hundred thirty-four point five six
intl()->number(1234.56)->ordinal();       // 1,235th
intl()->number(1234.56)->duration();      // 20:35
intl()->number(1234.56)->scientific();    // 1.23456E3

// Base:
intl()->number(1234.56)->format(\NumberFormatter::DECIMAL);

// The app's default locale
intl()->locale()->display();
// English

intl()->locale('zh_Hant_TW')->display();
// Chinese (Traditional, Taiwan)

intl()->locale('pt_BR')->region();
// Brazil

intl()->locale('de')->display('ru');
// немецкий

// The app's default currency
intl()->currency()->name();
// Euro

intl()->currency('RUB')->name('fr');
// rouble russe

intl()->currency('RUB')->symbol('ru');
// ₽ in a Russian locale

intl()->currency('RUB')->symbol('en');
// RUB in an English one

use Codewiser\Intl\Intl\Transliterator;

intl()->text()->convert('Шёлковый пух', Transliterator::RUSSIAN_LATIN);
// Shëlkovyy pukh

intl()->text()->convert('北京', Transliterator::HAN_LATIN);
// běi jīng

intl()->text()->normalize("e\u{0301}");     // é as one code point
intl()->text()->isNormalized($text);        // already in NFC?
shell
php artisan vendor:publish --tag=intl