This doesn't seem too hard. We know the following:
1 - 1st
2 - 2nd
3 - 3rd
4 - 4th
5 - 5th
6 - 6th
7 - 7th
8 - 8th
9 - 9th
10 - 10th
Basically, you can write a simple function that consists of nothing but a big if-then/else or set of case statements. You could be pulling the number from a db or from user input, whatever. Once you get it, analyze it and the manipulate it. Something like
function format_num($sNum)
{
$len = strlen($sNum);
$sLast_Dig = substr($sNum, $len - 1);
$sFormatted_Num = "";
switch ( $iLast_Dig )
{
case 1:
$formatted_num = $sNum . "st";
break;
case 2:
$formatted_num = $sNum . "nd";
break;
//etc...
}
return $formatted_num;
}
Now I didn't actually check this to see if there are any bugs, but the concept is there. Hope this helps.