Here's a PHP solution:
$day = Array('first','second','third','fourth','fifth','sixth','seventh',
'eighth','ninth','tenth','eleventh','twelfth');
$gifts = Array('Twelve drummers drumming,',
'Eleven pipers piping,',
'Ten lords a-leaping,',
'Nine ladies dancing,',
'Eight maids a-milking,',
'Seven swans a-swimming,',
'Six geese a-laying,',
'FIVE GOLDEN RINGS,',
'Four calling birds,',
'Three French hens,',
'Two turtle doves, and',
'A partridge in a pear tree');
for ($i = 0; $i < 12; ++$i) {
printf("On the $day[$i] of Christmas my true love gave to me\n" .
implode("\n", array_slice($gifts,-($i+1))) . "\n\n");
}