Forum Moderators: coopster

Message Too Old, No Replies

Number abbreviation

         

FiRe

9:44 pm on Jan 3, 2007 (gmt 0)

10+ Year Member



Is there any function or code to do this:

echo abbrev(1); //returns 1st
echo abbrev(2); //returns 2nd
echo abbrev(3); //returns 3rd

?

whoisgregg

9:59 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Those are called ordinal suffixes [zend.com] and that link goes to a function at the Zend codex for adding them. If that link gets pruned, a search at your favorite search engine for "php ordinal suffix" should get you plenty of options.

mcavic

10:04 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not that I know of, but you can write your own pretty easily. Just create an array with 9 rows, where you store the digits and their proper abbreviations.

Then, assuming you want to be able to handle numbers with more that one digit, just use the last digit of the number to do an array lookup.

Modulus is an easy way to get the last digit:
Number % 10 = last digit

coopster

11:07 pm on Jan 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Relative discussion from the past ...
Return Ordinal Suffixes with the date function [webmasterworld.com]