[RESOLVED] How to return integer as its text version (1 = 1st)
Hello
I need help. I cant figure out how to write a function to return a integer between 1 and whatever and return it as text like below.
1 returns 1st
3 returns 3rd
28 returns 28th
any help would be great, thank you
Re: [RESOLVED] How to return integer as its text version (1 = 1st)
Have a go atadapting this function which I found here, unless of course you only need numbers less than 100. Also, if you need this for a date then you can have it added on automatically using the date() function:
PHP Code:
<?php
function nthnum ($age,$small=0) { // proper ending for numbers, ie 2nd, 3rd, 8th
$last_char_age = substr("$age", -1);
switch($last_char_age) {
case '1' :
$th = 'st';
break;
case '2' :
$th = 'nd';
break;
case '3' :
$th = 'rd';
break;
default :
$th = 'th';
break;
}
if ($age > 10 && $age < 20) $th = 'th';
if (0 == $small) $niceage = $age.$th;
if (1 == $small) $niceage = $age."<sup>$th</sup>";
return $niceage;
}
?>