Old School PHP Scripts: Numword, the number to word converter

The Numword class (via Github) will rarely find a use, but its creation was primarily for fun. A friend of mine asked me if there was a PHP function that will turn a number into its word equivalent (example, 100 becomes one-hundred). As none existed, I felt like this would be a fun task to attempt, and so the Numword class was born. Numword supports the basic range of numbers and the ability to convert up to centillion (which is mind blowingly large).

The easiest way to convert a number is to use the single() method. This method accepts a single number argument and returns the word equivalent. You may also use the multiple() method which accepts an array of numbers. Do note however, that large numbers must be passed as a string, else it will blow up because of PHPs 32 bit integers.

// one-thousand, two-hundred thirty-four
Numword::single(1234);
// eight-billion, two-hundred thirty-four-million, seven-hundred eighty-thousand, two-hundred thirty-four
Numword::single('8234780234');

Some other convenient methods are block() and currency(). The block() method will parse out any numbers within a string of text, and convert them. While the currency() method is self explanatory, it converts currency.

// I am twenty-five years, fifteen days and sixty-two minutes years old.
Numword::block('I am 25 years, 15 days and 62 minutes years old.');
// one-thousand, three-hundred thirty-seven dollar(s) & fifteen cent(s)
Numword::currency('$1,337.15');

Awesome right? Furthermore, the currency() method is rather smart, in that it parses out the dollar sign, commas, and periods depending on the current locale based on setlocale(). You can also translate the strings used in currency() by passing an array as the second argument. But before we do that, lets go over translating the whole class.

Translating the strings in Numword is extremely easy, but also tedious. If you only need to translate for a single language, then you can overwrite the static properties. If you need to translate for multiple languages (user language selection system), then you will still need to overwrite the properties, but create some kind of system to know which language to use and when (possibly via includes). Here's an example translation of German; zero through nine respectively.

Numword::$digits = array('null', 'eins', 'zwei', 'drei', 'vier', 'fünf', 'sechs', 'sieben', 'acht', 'neun');

And to translate the currency strings, you can do something like:

Numword::currency('£48,530.38', array('dollar' => 'pound(s)', 'cent' => 'pence'));

Numword isn't as extensible as I would like, but since it is merely a fun project, the need for heavy translation and locale awareness settings aren't needed. You can always base your own class on Numword :). Hope you enjoyed!

Come have a Cupcake, open beta released!

The time has arrived, I have pushed my Cupcake Forum plugin into public beta. You may now download and use the plugin as you wish, but be weary because its still in beta, so problems may arise. If you run into a bug, please post it on the GitHub issues. I also want to thank Matt Curry for testing the plugin beforehand, just like he tested the Uploader plugin, so give him your thanks as well. Heres a quick overview of Cupcake:

The Cupcake Forum is a slimmed down version of the popular bulletin board system, packaged into a plugin. The plugin can be dropped into any CakePHP application and will run smoothly with a bit of configuration. The plugin comes bundled with all the basic features of a stand-alone system, some of which include topics, posts, users, polls, moderators, staff and more. For a full list, view the chapter regarding Features.
Donations

I was originally going to only sell the plugin, but chose against that, simply because it doesn't deserve to be purchased, if anything CakePHP as a whole does. So instead I have added a donation button underneath all the download buttons. So if you really really love my scripts, donate, or else ill take all my scripts down! Yeah maybe.

Cupcake forum plugin, it's pretty delicious

If you have been following me on Twitter, you may of heard me mention a new CakePHP plugin I am developing, a forum plugin. Well I am officially announcing it as the Cupcake Forum Plugin. It is basically complete, but I would like to run a few more tests and perhaps get an "installer" type script. Alongside this announcement, I have uploaded the forum plugin onto this domain as a demo, and will be using it as a support forum for all my scripts. Click the screenshot of the forum to view the demo.

Cupcake isn't as robust as regular forum systems, that would be absurd. Instead it has all the necessary basic features for fully utilizing a forum. Some of those features include: users and profiles, topics, replying, sub-forums, read topics, flood protection, topic auto lock, hourly post and topic limitations, access levels and permissions, moderators, searching, locking mechanisms, sticky and important topic types, topic and post reporting and many more. Oh and that's not all, it also comes bundled with a built in administration panel where you can manage all aspects of the forum, instead of having to do it manually in the database.

I will be releasing the plugin sometime this week. If you have any suggestions for features, be sure to send me an email or reply to this entry. Looking forward to all your feedback on this, it took quite a while to develop!

Databasic 2.1, now with more operator support!

I got pretty bored the other day and also noticed this contest over at NetTuts, and thought to myself, "Why not enter Databasic into the contest?". Well that is my plan, but I also wanted to fix some problems and restraints in the current version. The new version supports AND/OR operators in the conditions, as well the column operators (!=, <=, etc) have been rebuilt. With this change the new version is not backwards compatible! Sorry, but it shouldn't be too hard to fix your scripts to work correctly.

Here's a quick example of the new operator support in conditions.

$conditions = array(
    'OR' => array(
        array('name' => 'Miles'),
        array('name' => 'Johnson')
    ),
    'status' => 'active',
    'age >=' => 21
);

Download the new 2.1!
View the full change log and features

Feed Aggregator Component officially released!

I recently needed the ability to display a list of feed items, but the catch was I needed them to be combined from multiple feeds, a feed aggregator. At first I was expecting to find this in the bakery, but was saddened when there was none. So I sat down and began coding. I've never created a feed aggregator before, but it was relatively easy.

Its really simple, the script is a CakePHP Component that will take a list of feeds and aggregate them into a single array based on their timestamp. It works with RSS 1.0 (RDF), RSS 2.0 and Atom 1.0 and has the ability to cache its results.

View full documentation and download version 1.1

Enjoy! Let me know if there are any bugs.

Two new scripts, Resession and Decoda

It has been a while since I released some of my scripts, but now I have two to reveal! Well actually the Resession script has been up for nearly 2 months now, but I'm finally getting around to announcing. And without further ado, I give you Resession (Session Manager) and Decoda (A BBcode style parser).

Decoda

Decoda is a lightweight class that extracts and parses a custom markup language; based on the concept of BB code. Decoda supports all the basic HTML tags and manages special features for making links and emails auto-clickable, using shorthand emails and links, and finally allowing the user to add their own code tags.

Download the latest versions of Decoda

Resession

A small lightweight script that can manage and manipulate Session data. Calls session_start() in memory so that no header errors are thrown, as well as stores the session id in the object.

Download the latest version of Resession

If you have any suggestions for either of these classes, please feel free to comment this post or send me an email!

Numword officially released

So I'm releasing this fun little script I built a few months ago, it's called Numword. This script will take a number and convert it into its word equivalent. For example, 12 will become twelve, and 7 will become seven. Now why did I create this? Well one day a friend asked me if there was a PHP function that would do this, but there wasn't, so I set out and a few hours later it was done! I thought it would be a good idea to release this to the public, for anyone who might need something like this, as rare as it would be. Enjoy!

Download Numword v1.2
View the complete change log