...

View Full Version : add_ordinals in PHP



me'
04-12-2004, 08:30 PM
http://www.codingforums.com/showthread.php?p=178925#post178925

A beautiful javascript function as the result of the best minds on this forum coming together, but I'm trying to rewrite it in PHP. Maybe because I don't fully understand the Javascript in it, but this function always seems to return 'th'.
function add_ordinals($num){
$ords = array ( "th","st","nd","rd" );
return
$num . $ords[(!((($num=this%10) >3) || (floor(this%100/10)==1))) * $num];
}Any help in debugging is appreciated.

Garadon
04-12-2004, 09:42 PM
how about this? (ain't english so not to fluent in ordinals)

function toOrdinal($num)
{
$ords = array ( "st","nd","rd" ,"th");
return $num .$ords[(($num%10<4)&&($num%10>0)&&(floor($num%100/10)!=1))?($num%10-1):3];
}

sidney
04-12-2004, 11:30 PM
a ord on numbers using date function


<?php
$a=array(1,2,3,4,5,6,7,8,22,21,101,31);
foreach($a as $b)
{
$ord=date("S",((substr($b,-1,1)*86400)-86400));
echo $b.$ord."<br>";
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum