Introduction
PHP-NTL is a powerful PHP library that converts numbers into their
word representation. Supporting numbers from
0
to
999,999,999,999
, with built-in support for both French and English languages.
Installation
There are two ways to install PHP-NTL:
1. Direct Download
Download the
NumberToLetter.php
file and include it in your project:
require_once 'path/to/NumberToLetter.php';
2. Clone Repository
git clone https://github.com/branGitFox/PHP-NumberToLetter-library.git
Usage
Basic Usage
Create a new instance of NumberToLetter with a number and optional language parameter:
// French (default)
$ntl = new NumberToLetter(12345);
echo $ntl->numberToLetter(); // douze mille trois cent quarante-cinq
// English
$ntl = new NumberToLetter(12345, 'ENG');
echo $ntl->numberToLetter(); // twelve thousand three hundred forty five
Language Support
The library supports two languages:
- 'FR' - French (default)
- 'ENG' - English
Examples
Converting Numbers
$ntl = new NumberToLetter(1234567, 'FR');
echo $ntl->numberToLetter();
// Output: un million deux cent trente quatre mille cinq cent soixante-sept
$ntl = new NumberToLetter(1234567, 'ENG');
echo $ntl->numberToLetter();
// Output: one million two hundred thirty four thousand five hundred sixty seven
Batch Testing
Use the static makeTest method to convert a range of numbers:
// Test numbers from 0 to 10 in English
NumberToLetter::makeTest(0, 10, 'ENG');
// Test numbers from 0 to 10 in French
NumberToLetter::makeTest(0, 10, 'FR');
API Reference
Constructor
__construct(int $number, string $lang = 'FR')
- $number - The number to convert (0 to 999,999,999,999)
- $lang - Language code ('FR' or 'ENG')
Methods
numberToLetter()
Converts the number to its word representation.
static makeTest(int $from, int $to, string $lang)
Converts a range of numbers to words.
Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
-
Create a new branch (
git checkout -b feature/improvement
) - Make your changes
-
Commit your changes (
git commit -am 'Add new feature'
) -
Push to the branch (
git push origin feature/improvement
) - Create a Pull Request