fyre / formatter
A formatting library.
v3.1.0
2024-10-11 12:51 UTC
Requires
- fyre/datetime: ^3.0
- fyre/typeparser: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^10
README
FyreFormatter is a free, open-source formatting library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/formatter
In PHP:
use Fyre\Utility\Formatter;
Methods
Currency
Format a value as a currency string.
$value
is a string or number representing the value to format.$options
is an array containing formatting options.$locale
is a string representing the locale, and will default to the Formatter default locale.$currency
is a string representing the currency, and will default to the Formatter default currency.
$currency = Formatter::currency($value, $options);
Date
Format a DateTime as a date string.
$value
is a DateTime.$options
is an array containing formatting options.$locale
is a string representing the locale, and will default to the Formatter default locale.$timeZone
is a string representing the time zone, and will default to the Formatter default time zone.$format
is a string representing the format, and will default to the TypeParser default date user format.
$date = Formatter::date($value, $options);
Date/Time
Format a DateTime as a date/time string.
$value
is a DateTime.$options
is an array containing formatting options.$locale
is a string representing the locale, and will default to the Formatter default locale.$timeZone
is a string representing the time zone, and will default to the Formatter default time zone.$format
is a string representing the format, and will default to the TypeParser default datetime user format.
$datetime = Formatter::datetime($value, $options);
Get Default Currency
Get the default currency.
$defaultCurrency = Formatter::getDefaultCurrency();
Get Default Locale
Get the default locale.
$defaultLocale = Formatter::getDefaultLocale();
Get Default Time Zone
Get the default time zone.
$defaultTimeZone = Formatter::getDefaultTimeZone();
Number
Format a value as a number string.
$value
is a string or number representing the value to format.$options
is an array containing formatting options.$locale
is a string representing the locale, and will default to the Formatter default locale.
$number = Formatter::number($value, $options);
Percent
Format a value as a percent string.
$value
is a string or number representing the value to format.$options
is an array containing formatting options.$locale
is a string representing the locale, and will default to the Formatter default locale.
$percent = Formatter::percent($value, $options);
Set Default Currency
Set the default currency.
$currency
is a string representing the currency code, or a Closure that returns the currency code.
Formatter::setDefaultCurrency($currency);
Set Default Locale
Set the default locale.
$locale
is a string representing the locale, or a Closure that returns the locale.
Formatter::setDefaultLocale($locale);
Set Default Time Zone
Set the default time zone.
$timeZone
is a string representing the time zone, or a Closure that returns the time zone.
Formatter::setDefaultTimeZone($timeZone);
Time
Format a DateTime as a time string.
$value
is a DateTime.$options
is an array containing formatting options.$locale
is a string representing the locale, and will default to the Formatter default locale.$timeZone
is a string representing the time zone, and will default to the Formatter default time zone.$format
is a string representing the format, and will default to the TypeParser default time user format.
$time = Formatter::time($value, $options);