Taylor_1978
11-22-2006, 05:36 AM
I've searched PHP and it's more than likely a simple solution I just can't find. How do I turn a variable of 1 to 1st, 2 to 2nd etc...
Thanks in advance! :thumbsup:
Thanks in advance! :thumbsup:
|
||||
1'st' 2'nd 3'rd' etcTaylor_1978 11-22-2006, 05:36 AM I've searched PHP and it's more than likely a simple solution I just can't find. How do I turn a variable of 1 to 1st, 2 to 2nd etc... Thanks in advance! :thumbsup: CFMaBiSmAd 11-22-2006, 05:52 AM You can use the date() function with the "S" format parameter for 1-31. Beyond that you would need to create your own function. felgall 11-22-2006, 10:47 PM switch(day) { 1: 21: 31: day.='st'; break; 2: 22: day.='nd'; break; 3: 23: day.='rd'; break; default: day.='th'; } gsnedders 11-23-2006, 06:24 PM Both those assume it's a date, here's one that doesn't: function nth($in) { if(strlen($in)>1 && substr($in,-2,1)==1) return $in."th"; switch(substr($in,-1,1)) { case 1: return $in."st"; case 2: return $in."nd"; case 3: return $in."rd"; default: return $in."th"; } } |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum