SCook Posted October 30, 2008 Share Posted October 30, 2008 Hi all, Got another tone :-) Is there a built in function to format a number to it's appropirate suffix? I'm sure there is, and it'd save me time to write my own function, like: 1 = 1st 3 = 3rd 51 = 51st and etc. Thanks Link to comment https://forums.phpfreaks.com/topic/130737-formatting-a-number-suffix-lik-eth-st-nd-etc/ Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 You can use the date() function for numbers between 1 and 31. After that you're on your own: <?php for ($i=1;$i<32;$i++) echo date('jS',strtotime('2008-01-' . $i)) . '<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/130737-formatting-a-number-suffix-lik-eth-st-nd-etc/#findComment-678465 Share on other sites More sharing options...
thebadbad Posted October 30, 2008 Share Posted October 30, 2008 You can find some functions in the comments of the is_numeric() manual. Link to comment https://forums.phpfreaks.com/topic/130737-formatting-a-number-suffix-lik-eth-st-nd-etc/#findComment-678474 Share on other sites More sharing options...
SCook Posted October 30, 2008 Author Share Posted October 30, 2008 Well, I suppose I can use the date function, I've thought of that. What I suppose I can do is split the number string and apply the date to the final digit, as this is the only thing that matters. However, ou run into a weierd problem with the teens. They're all "th" So I guess I'll have to figure something out. Maybe the is_mumeric can help Link to comment https://forums.phpfreaks.com/topic/130737-formatting-a-number-suffix-lik-eth-st-nd-etc/#findComment-678487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.