PHP Classes
PHP Classes
elePHPant
Icontem

PHP Tutorial on How to Convert English Words to Numbers - PHP Convert Words to Numbers package blog

Recommend this page to a friend!
  All package blogs All package blogs   PHP Convert Words to Numbers PHP Convert Words to Numbers   Blog PHP Convert Words to Numbers package blog   RSS 1.0 feed RSS 2.0 feed   Blog PHP Tutorial on How t...  
  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  

Author:

Posted on:

Package: PHP Convert Words to Numbers

There are many solutions for spelling numbers using words in English or other language. However, doing the opposite is not so easy.

The PHP Words to Numbers package does that. It takes number expressed in English works and returns the number value that it represents.




Contents

What is the PHP Convert Words to Number package?

The Challenges Faced to Make this PHP Package Work

Package Features

Limitations

Conclusion

PHP Convert Words to Numbers

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 Work

The 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.

Package Features

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" );

Limitations

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.

Conclusion

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,427,109 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:

FacebookGmail
HotmailStackOverflow
GitHubYahoo


Comments:

No comments were submitted yet.




  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  
  All package blogs All package blogs   PHP Convert Words to Numbers PHP Convert Words to Numbers   Blog PHP Convert Words to Numbers package blog   RSS 1.0 feed RSS 2.0 feed   Blog PHP Tutorial on How t...