Download the PHP package neuron-php/formatting without Composer
On this page you can find all versions of the php package neuron-php/formatting. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package formatting
Neuron-PHP Formatting
Formatters that turn raw values into currency, dates, times, and phone numbers. Each one implements Neuron\Formatters\IFormatter.
format() returns null when a date cannot be recognized.
Installation
Requires PHP 8.4 or higher and neuron-php/core.
Currency
Currency prints a symbol, pads the amount on the left, and formats it with sprintf. The defaults are $, nine characters of padding with _, and %01.2f (two decimal places).
Shorten the pad:
The setters return the formatter, so they can be chained. setFormat() changes the sprintf pattern used for the number.
Date
Date reads a date and prints it with PHP's date() format. The default format is Y-m-d.
The incoming date may use -, /, or . as the separator, in any of these orders:
yyyy-mm-ddmm-dd-yyyydd-mm-yyyy
When the first number could be either a month or a day, it is read as a month. 23/12/2024 is read as a day first, because 23 is not a month. A value that is not a date returns null.
setFormat() takes a PHP date format.
DateTime
DateTime normalizes the date the same way Date does, then formats the date and time together. The default format is Y-m-d g:i a.
A 12-hour clock with a meridian is accepted too: 23/12/2024 1:30 pm.
Time
Time formats a time of day. The default format is g:i a.
PhoneNumber
PhoneNumber strips everything that is not a digit, then formats by length.
| Digits | Result |
|---|---|
| 7 | 123-4567 |
| 10 | 123-456-7890 |
| More than 10 | A leading +, the extra digits as a country code, then the last ten digits grouped as 2, 3, and 5 |
| Anything else | The digits, unchanged |
More Information
- Neuron Framework: neuronphp.com
- GitHub: github.com/neuron-php/formatting
- Packagist: packagist.org/packages/neuron-php/formatting
License
MIT License - see LICENSE file for details