Converts Words To Numbers
Add to composer.json's repositories
array
"repositories": [
{
"type": "vcs",
"url": "https://github.com/daraeman/WordToNumber.git"
}
]
Run composer update
to install.
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
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.
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.
Lists the available languages
Set the language that should be used to parse the text
Name, (array) Data ) Creates or replaces a language's data.
Takes an array that should be formatted as the default english one.
$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)