A PHP package for converting numbers to a human readable sentence of it's ordinal form eg. 'first', 'second' or even 'Three thousand five hundred and sixty first'
Latest release supports numbers in the range 1 - 9999.
Recomended installation via Composer:
composer require martinjoiner/ordinal-number
See library page on Packagist https://packagist.org/packages/martinjoiner/ordinal-number
// Tell our code to use the namespace
use MartinJoiner\OrdinalNumber\OrdinalNumber;
// The following line will output 'three hundred seventy eighth'
print OrdinalNumber::convert( 378 );
// The following line will output 'three hundred and seventy eighth'
print OrdinalNumber::convert( 378, true );
// The following line will output 'Three hundred and seventy eighth' (notice capitalised)
print OrdinalNumber::convert( 378, true, true );
- num {integer} A number to be converted (in the range of 1 - 9999)
- appendAnd {boolean} - Default: false - Places the word 'and' before the final 2 parts if number above 101 or higher (eg. One hundred and first). Added to support both American and European versions of English language.
- titleCase {boolean} - Default: false - Capitalises the first letter
To see some working examples simply run index.php
Tests are written in PHPUnit https://phpunit.de/
phpunit --bootstrap vendor/autoload.php tests/OrdinalNumberTest