List Writer and Terminal Illness

“Illness” in the Hip Hop sense of the word and “terminal” in the Linux sense of the word. Don’t rejoice, I’m not dying yet! But first…

List Writer

This is a tiny and straightforward function but I have a feeling it’s going to come in useful, so I’ll put it here for safe keeping. It takes an array and simply writes it out as you would in English. There is an example below.

     * Writes an array as a list in proper English. Commas and all.

    function write_list($arr){
        $size = sizeof($arr); 
        $n    = 1;
        $out  = '';
        foreach($arr as $item){
            if ($n == $size){
                $out .= ' '.$item;
            } else if ($n == ($size-1)){
                $out .= ' '.$item.' and';
            } else {
                $out .= ' '.$item.',';
        return $out;
    $list = array(  'Queen Elizabeth II',
                    'a paperweight',
                    'a feeling of ennui',
    echo 'In my bag I have '.write_list($list) . '. It\'s quite a big bag.';

The above would output the following:

In my bag I have Queen Elizabeth II, a paperweight, Batman, a feeling of ennui and Switzerland. It's quite a big bag.

Terminal Illness
My main coding project at the moment (apart from the big one, which I’m not allowed to talk about…more on that another time) is a web page that looks and acts like a command-line. I started this after looking at, the unofficial Google command line. “How would you go about making that, then?” a friend asked. And I thought about it. “Like this”, I said and 5 minutes later I had a basic mock-up.

Since then it has gone through a number of iterations. I have now condensed and generalised it into a re-usable class that is easy to expand and customise. It’s not quite ready for public consumption yet but as soon as it is I will release the source code.

I am also using creating a text-based adventure MMO game based on this system… More about that soon.

Edit: oh, you’ll probably want a link!


About Mr Chimp

I make music, draw pictures, browse the internet, programme, and make sweet, sweet cups of tea until the early hours.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s