Author: Mohammed Asad
Posted on: 2017-01-04
Package: PHP Convert Words to Numbers
The PHP Words to Numbers package does that. It takes number expressed in English works and returns the number value that it represents.
What is the PHP Convert Words to Number package?
The Challenges Faced to Make this PHP Package Work
What is the PHP Convert Words to Number package?The PHP Convert Words to Numbers package was created for converting a string with words that represents back to the digits to the original number, like for instance thousand to 1000, hundred to 100 or so on.
The main reason why I created this package was to help another developer who was looking for this. Since I got some free time, I have written it after some research.
The Challenges Faced to Make this PHP Package WorkThe development of this package was not trivial. There were a few challenges that were faced to make it work with many variants of representation of numbers as text in English.
One of the problems is that sometimes the order of the words for to represent the same number may be different.
Also users sometimes commit spelling mistakes, or using extra spaces between words or even enter unexpected characters.
The package also supports the way to represent numbers either in western English or Indian western using for instance words like billion or crore.
This package supports several interesting like for instance that it can automatically detect whether the entered number English variant is either be western or indian.
It can also get the numbers for terms like twelve hundred or twenty five hundred.
The package can also perform the sum of expression like twelve hundred and twelve hundred and twenty three hundred.
The returned values can be returned as an integer or a string formatted according to whether the detected language ie western or Indian English.
This package is pretty simple to use. Just create an object and call the displayNumbers method.
$objWordsToNumbers = new cWordsToNumbers(); echo $objWordsToNumbers -> displayNumbers( "ninty thousand nine hundred and ninty nine" );
Currently the package still has a few limitations. For instance the Indian numbers limit is ninety nine lakh crore and ninty nine lakh and so on (99,99,999,99,99,999).
The western numbers limit is nine hundred and ninety nine billion and so on (999,999,999,999).
Also using words in the wrong order might return undesired results.
The PHP Convert Words to Numbers class performs an unusual operation of reverting of text spelling a given amount as English words into the original number.
Despite it is a difficult process that may fail in some unexpected cases, it works well in general and may be useful to many developers with applications that need to parse text with number amounts.
If you liked this article, please share it with other developers. If you have questions post your comments here.
You need to be a registered user or login to post a comment
1,434,905 PHP developers registered to the PHP Classes site.
Be One of Us!
Login Immediately with your account on:
No comments were submitted yet.