tags:

views:

32

answers:

2

Hi. I'm working on a relatively rudimentary project which requires using a text-to-speech engine to read the current time. PHP will allow me to output the current time in many ways. However, I need to output the time as words. For example, 13:00 should output as "one o'clock pm" and so forth. Another example, 01:23 should output as "one twenty three am".

I've searched for some scripts, and attempted to use my terribly amateurish PHP skills to accomplish this, but so far I am unable to complete the task.

Does anyone know of an existing script, written in PHP, that can do this? All we're looking to do is read the system time, apply an offset for time zone, then take the resulting time and output as words. I can give any clarification needed.

Thank you!

+1  A: 

There is a PEAR package that translates numbers to words (note however that I haven't used it personally).

You could add in some extra logic to translate 00 as "o'clock", and get AM or PM from date("A") (or check if the hour is > 12).

Daniel Vandersluis
Daniel, thanks for the comment. Unfortunately, we're a bit limited in the environment given us, and we won't be able to leverage PEAR. It would be nice, however.
Well you could install a pear script manually (without pear), or take a look at how they're doing to give you an idea of how to recreate the functionality. For your purposes it shouldn't be too complex, either, because you just need to handle 0-59.
Daniel Vandersluis
+1  A: 

I reckon you can get most of the way with the standard PHP libs:

echo date('l F j, Y g:ia') . "\n";

See here: http://uk3.php.net/manual/en/function.date.php

Robin