Download the PHP package knppy/units without Composer

On this page you can find all versions of the php package knppy/units. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package units

Units

Packagist PHP from Packagist GitHub Workflow Status (master) Total Downloads

Knppy units is a PHP library to make working with units safer, easier, and fun!

Installation

You can install the package via Composer:

Usage

Lists implement Knppy\Units\Contract\UnitOfMeasurements, so other lists can be added alongside the International System of Units. CookingUnitOfMeasurements covers cooking: volumes (tsp, tbsp, cup, ...), masses (oz, lb), counts (clove, slice, ...) and imprecise amounts (pinch, dash, handful, ...).

Conversion

Each system of units has its own converter implementing Knppy\Units\Contract\UnitConverter. convertTo() uses the SIUnitConverter by default; pass another converter as the second argument.

All 24 SI prefixes (quecto to quetta) are supported through the Prefix enum and the SIUnitConverter:

Amounts are whole numbers, so convert() throws when the result would have decimals. Use convertToDecimal() for an exact decimal string instead. Masses can be prefixed grams (mg) even though the SI base unit is the kilogram.

Cooking

The CookingUnitConverter converts volumes and masses using exact US customary ratios:

Units without a fixed size, such as a pinch or a clove, cannot be converted to another unit and throw an IncompatibleUnitOfMeasurementException.

Languages

Unit names can be localized and localized input can be parsed back to a unit. The symbol stays the canonical identifier, so conversion and equals are unaffected.

The count picks the plural form by the CLDR rules of the locale (via ext-intl), so languages with more than two forms work. Pass a unit's amount directly:

Symbols are matched first (case-sensitive), then names, plurals and aliases (case-insensitive). Unsupported locales and missing units fall back to English. SIUnitNames does the same for SI units.

Available locales: en, nl, de, fr, es, pt, zh, ja, ru, hi, ar. Quantity labels are not localized yet. Requires ext-intl and ext-mbstring.

Prefixes

SIUnitNames also names and parses prefixed units, composing them from the prefix and the unit name:

Parsing ignores case and common Latin accents (kilometro matches kilómetro). Units that cannot take a prefix (kg, °C) are rejected, as in SIUnitConverter.

Spelling that cannot be composed is data, not code. A locale can list prefixed names in si-prefixed.php (Spanish and Portuguese do this for the stress shift in kilómetro), or give a unit a prefixed entry with its own forms and a separator (Arabic does this for ميلي ثانية). Region tags work too: pt is Brazilian (quilômetro) and pt-PT is European (quilómetro).

Parsing

Parsers turn a string into a Unit and implement Knppy\Units\Contract\UnitParser. They throw a ParserException when the input is not a whole amount with a unit of measurement.

SymbolUnitParser accepts any symbol, so put it last in an AggregateUnitParser.

Formatting

Formatters turn a Unit into a string and implement Knppy\Units\Contract\UnitFormatter, the counterpart of the parsers.

LocalizedUnitFormatter picks the plural form from the amount and groups digits as the locale does (pass grouping: false to get output LocalizedUnitParser can read back). Amounts beyond the integer range keep every digit.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Thank you for considering contributing to Units! Please review our contributing guide to get started.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

Units is open-sourced software licensed under the MIT license.


All versions of units with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-bcmath Version *
ext-intl Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package knppy/units contains the following files

Loading the files please wait ...