Skip to content

Latest commit

 

History

History
61 lines (47 loc) · 2.06 KB

README.md

File metadata and controls

61 lines (47 loc) · 2.06 KB

WordToNumber

Converts Words To Numbers

Build Status

Installation

Add to composer.json's repositories array

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/daraeman/WordToNumber.git"
    }
]

Run composer update to install.

Usage

string/FALSE parse( string )

Parse the supplied text and convert all number-words found into a single number "eight hundred fifteen".
The String need not only be word-numbers, but should contain only one word-number, as having multiple will cause undefined behavior
Words do not need to have any specific separator or case, or even any separator at all ninetEENthousandeighTY-eight
Returns the number in string form, or FALSE

setValidatorWhitelist( string/array )

Takes a single, or array of regex strings to test numbers against before parsing.
Non-matching values will be excluded.
This is run after setValidatorBlacklist.
Passing a falsey value will clear the list.

setValidatorBlacklist( string/array )

Takes a single, or array of regex strings to test numbers against before parsing.
Matching values will be excluded.
This is run before setValidatorWhitelist.
Passing a falsey value will clear the list.

array listLanguages()

Lists the available languages

bool setLanguage( (array) languageName )

Set the language that should be used to parse the text

updateLanguageData( string )

Name, (array) Data ) Creates or replaces a language's data.
Takes an array that should be formatted as the default english one.

Example

$wordtoNumber = new wordToNumber();
$wordtoNumber->setValidatorBlacklist( '/hundred/i' );
$wordtoNumber->setValidatorWhitelist([
	'/one|two|three|four/i',
	'/five|six|seven|eight/i'
]);
$number = $wordtoNumber->parse( 'eight' );
var_dump( $number );
// string(1) "8"
$number = $wordtoNumber->parse( 'eight hundred' );
var_dump( $number );
// bool(false)