djunehor / word-to-number
Transform words to numbers
Installs: 2 114
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^7.1
Requires (Dev)
- kwn/number-to-words: dev-master
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2024-12-19 16:14:58 UTC
README
This PHP package allows you to convert numbers written in words to integers.
Installation
You can install the package via composer:
composer require djunehor/word-to-number
Usage
use Djunehor\Number\WordToNumber; $wordToNumber = new WordToNumber(); $wordTransformer = $wordToNumber->getWordTransformer(); // you can specify locale via: $wordToNumber->getWordTransformer('en'); $number = $wordTransformer->toNumber($word);
Via Helper
$number = word_to_number($word); // default locale is en $number = word_to_number($word, 'yo'); // specify Yoruba locale
Available Locales
Adding New Locale
- In
Locales
directory, createYourLocaleTransformer
class that implementsWordTransformer
- Ensure there's a
toNumber()
method that accepts string and returns int - Add
YourLocaleTransformer::class
to$wordTransformers
array inWordToNumber
- Ensure the class pass tests
- Update the Readme Available Locales section with your newly added locale
- Create a Pull Request