<?php
$numberFormatter = new NumberFormatter('de_CH', NumberFormatter::DECIMAL);
echo $numberFormatter->format(1000.45);
$numberFormatter = new NumberFormatter('de_CH', NumberFormatter::CURRENCY);
echo $numberFormatter->format(1000.45);
echo $numberFormatter->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
1'000.45
<?php
$numberFormatter = new NumberFormatter('de_CH', NumberFormatter::DECIMAL);
echo $numberFormatter->parse('1\'000.45');
1000.45
<?php
$dateFormatter = new IntlDateFormatter('it_IT', IntlDateFormatter::LONG,
IntlDateFormatter::SHORT);
$date = new DateTime();
echo $dateFormatter->format($date) . PHP_EOL;
echo $dateFormatter->format(1390252923);
18 aprile 2016 21:51
<?php
$dateFormatter = new IntlDateFormatter('it_IT', IntlDateFormatter::LONG,
IntlDateFormatter::SHORT);
echo $dateFormatter->parse('20 gennaio 2014 22:22');
1390252920
<?php
$text = 'Am {dateval,date,full} waren es {visitor,number,integer} Besucher.';
$msgDe = new MessageFormatter('de_DE', $text);
$msgCh = new MessageFormatter('de_CH', $text);
$args = array(
'visitor' => 1240000,
'dateval' => new DateTime(),
);
echo $msgDe->format($args);
echo $msgCh->format($args);
Am Sonntag, 17. April 2016 waren es 1.240.000 Besucher.
<?php
$text = 'Am {dateval,date,full} waren es {visitor,number,integer} Besucher.';
$args = array(
'visitor' => 1240000,
'dateval' => new DateTime(),
);
echo MessageFormatter::formatMessage('de_DE', $text, $args);
Am Sonntag, 17. April 2016 waren es 1.240.000 Besucher.
Type | Style |
---|---|
number | (none) |
integer | |
currency | |
percent | |
(styletext) |
Type | Style |
---|---|
date | (none) |
short | |
medium | |
long | |
full | |
(styletext) |
Type | Style |
---|---|
time | (none) |
short | |
medium | |
long | |
full | |
(styletext) |
Type | Style |
---|---|
spellout | |
ordinal | |
duration |
<?php
$calendar = IntlCalendar::createInstance('Europe/Berlin', 'de_DE');
var_dump(
$calendar->getTime(),
$calendar->getType(),
$calendar->isWeekend(),
$calendar->get(IntlCalendar::FIELD_YEAR),
$calendar->inDaylightTime()
);
1461093920108
<?php
$calendar = IntlCalendar::createInstance('Europe/Berlin', 'de_DE');
while (false === $calendar->isWeekend()) {
echo 'All work and no play makes me a dull dev. ';
$calendar->setTime(IntlCalendar::getNow());
}
echo 'Yay.';
Mo. | Di. | Mi. | Do. | Fr. | Sa. | So. |
28 | 29 | 30 | 31 | 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 1 |
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
27 | 28 | 29 | 30 | 31 | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
<?php
$timezone = IntlTimeZone::createTimeZone('Europe/Berlin');
$timezone2 = IntlTimeZone::createTimeZone('Europe/Paris');
var_dump(
$timezone->getDisplayName(),
$timezone->hasSameRules($timezone2),
$timezone->useDaylightTime(),
$timezone->getRawOffset()
);
Central European Standard Time
<?php
var_dump(Locale::getDefault());
Locale::setDefault('de_DE');
var_dump(Locale::getDefault());
en_US_POSIX
<?php
var_dump(
Locale::getDisplayRegion('de_DE', 'de'),
Locale::getDisplayRegion('de_DE', 'it'),
Locale::getDisplayRegion('de_DE', 'en')
);
Deutschland
<?php
var_dump(
Locale::getDisplayLanguage('de_DE', 'de'),
Locale::getDisplayLanguage('de_DE', 'it'),
Locale::getDisplayLanguage('de_DE', 'en')
);
Deutsch
<?php
$spoof = new Spoofchecker();
// are strings visually confusable?
var_dump(
$spoof->areConfusable("Körner", "Körner\0"),
$spoof->areConfusable("Körner", "Korner"),
$spoof->areConfusable('lol', '1o1'),
$spoof->areConfusable('lol', 'IoI')
);
false
<?php
$uconv = new UConverter('UTF-8', 'latin-1');
echo $uconv->convert('coraz�n');
echo UConverter::transcode('coraz�n', 'UTF-8', 'latin-1');
corazón
<?php
$text = "Si contano i danni. A Pescara, ".
"1.500 sfollati per l'esondazione del Fosso Vallelunga. ".
"Dall'inizio dell'anno l'agricoltura ha subito un miliardo ".
"di euro di danni.";
$i = IntlBreakIterator::createSentenceInstance('it_IT');
$i->setText($text);
foreach($i->getPartsIterator() as $sentence) {
echo $sentence . PHP_EOL . '----- next -----' . PHP_EOL;
}
Si contano i danni.
<?php
$array = array('a', 'g', 'A', 'ß', 'ä', 'j', 'z');
sort($array);
sort = A,a,g,j,z,ß,ä
<?php
$array = array('a', 'g', 'A', 'ß', 'ä', 'j', 'z');
$collator = new Collator('de_DE');
$collator->setAttribute(Collator::CASE_FIRST, Collator::LOWER_FIRST);
$collator->sort($array);
Collator::sort = a,A,ä,g,j,ß,z
<?php
$trans = Transliterator::create('Any-Latin');
echo $trans->transliterate('こんにちは');
kon'nichiha
<?php
var_dump(Transliterator::listIDs());
array(286) {
[0]=>
string(11) "ASCII-Latin"
[1]=>
string(11) "Latin-Arabic"
...
<?php
// returns null on error on PHP < 7.0
$curr = new ResourceBundle('it', __DIR__ . '/resources');
// get old german currency
$demCurrency = $curr->get('Currencies')
->get('DEM');
echo $demCurrency->get(0) . PHP_EOL;
echo $demCurrency->get(1) . PHP_EOL;
DEMit{ Currencies{ ADP{ "ADP", "Peseta Andorrana", } .... DEM{ "DEM", "Marco Tedesco", }
genrb -d /path/to/resources/currency/ it.txt
Created resource: it.res
<?php
echo IntlChar::toupper('ä');
echo IntlChar::tolower('Č');
echo IntlChar::chr(9730);
Ä
<?php
var_dump(IntlChar::isUUppercase('A'));
var_dump(IntlChar::isULowercase('A'));
var_dump(IntlChar::isdigit(3));
var_dump(IntlChar::isdigit('3'));
var_dump(IntlChar::isspace(' '));
true
<?php
echo IntlChar::charName('Ü');
LATIN CAPITAL LETTER U WITH DIAERESIS
<?php
// Exists since PHP 5.5 for php.ini
ini_set('intl.use_exceptions', true);
try {
$curr = new ResourceBundle('IDontExist', __DIR__);
} catch (IntlException $e) {
echo $e->getMessage();
}
resourcebundle_ctor: Cannot load libICU resource bundle
<?php
$intlFormat = (new Budgegeria\IntlFormat\Factory())->createIntlFormat('en_US');
$date = new DateTime();
$number = 1002.25;
echo $intlFormat->format('At %time_short the value was %number', $date, $number);
At 5:30 AM the value was 1,002.25