A quick search of the Web shows that there is an existing PEAR package.
minifairy wrote:not some sort of some long convoluted If($x==3) echo "Three"; this could take forever.
Then you probably should try to implement this, at least for a limited yet sufficiently large range of numbers, as an exercise.