PHP Classes


Recommend this page to a friend!
  Classes of Zacchaeus Bolaji  >  PHP Word to Number  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Word to Number
Convert a string with amount in words to a number
Author: By
Last change:
Date: 1 month ago
Size: 2,548 bytes



Class file image Download

Word To Number

CircleCI Latest Stable Version Total Downloads License Build Status Scrutinizer Code Quality Code Coverage StyleCI

This PHP package allows you convert numbers written in words to integers


You can install the package via composer:

composer require djunehor/word-to-number


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

|Language|Code|Test| |:--------- | :-----------------: | :------: | |English|en|Yes|

Adding New Locale

  • In Locales directory, create YourLocaleTransformer class that implements WordTransformer
  • Ensure there's a toNumber() method that accepts string and returns int
  • Add YourLocaleTransformer::class to $wordTransformers array in WordToNumber
  • Ensure the class pass tests
  • Update the Readme Available Locales section with your newly added locale
  • Create a Pull Request