PHP Classes

PHP Word to Number: Convert a string with amount in words to a number

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 77 All time: 10,159 This week: 673Up
Version License PHP version Categories
php-word-to-number 1.0The PHP License7PHP 5, Text processing, Finances
Description 

Author

This package can convert a string with amount in words to a number.

It can take a text string that has words that express a given amount and parses it to extract the number that it represents.

The package can potentially support processing number strings in multiple languages. Currently it supports converting strings to numbers in English.

Picture of Zacchaeus Bolaji
  Performance   Level  
Name: Zacchaeus Bolaji <contact>
Classes: 17 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 245415 in Nigeria Nigeria
Week rank: 180 Up5 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 12x

Winner: 1x

Documentation

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

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

|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

  Files folder image Files (11)  
File Role Description
Files folder image.circleci (1 file)
Files folder imagesrc (1 file, 2 directories)
Files folder imagetests (1 file)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (11)  /  .circleci  
File Role Description
  Accessible without login Plain text file config.yml Data Auxiliary data

  Files folder image Files (11)  /  src  
File Role Description
Files folder imageHelpers (1 file)
Files folder imageLocales (2 files)
  Plain text file WordToNumber.php Class Class source

  Files folder image Files (11)  /  src  /  Helpers  
File Role Description
  Accessible without login Plain text file helpers.php Aux. Auxiliary script

  Files folder image Files (11)  /  src  /  Locales  
File Role Description
  Plain text file EnglishWordTransformer.php Class Class source
  Plain text file WordTransformer.php Class Class source

  Files folder image Files (11)  /  tests  
File Role Description
  Plain text file WordTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:77
This week:0
All time:10,159
This week:673Up