#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    43
    Rep Power
    15
    How can I display the number 1 to be "1st",the number 2 to be "2nd" etc?

    Thanks,

    Weldon
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    24
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    function ordinal($number) {
    $number = abs((int)$number);
    $check = substr($number,-1,1);
    $check = ( (substr($number,-2,1) == "1" && $number >= 10) ? 4 : $check );

    switch($check) {
    case 1: return("st");
    case 2: return("nd");
    case 3: return("rd");
    default: return("th");
    }
    }

    $my_number = 1;
    echo "ordinal for $my_number is $my_number".ordinal($my_number)."<br>";
    $my_number = 2;
    echo "ordinal for $my_number is $my_number".ordinal($my_number)."<br>";
    $my_number = 3;
    echo "ordinal for $my_number is $my_number".ordinal($my_number)."<br>";
    $my_number = 4;
    echo "ordinal for $my_number is $my_number".ordinal($my_number)."<br>";

    ?>
    [/code]

    ------------------
    - weeder

Similar Threads

  1. Array of ten integers
    By deerslayer in forum Visual Basic Programming
    Replies: 2
    Last Post: December 5th, 2003, 11:50 PM
  2. scanning a char buffer for integers
    By kavi_s in forum C Programming
    Replies: 2
    Last Post: June 9th, 2003, 11:06 AM
  3. help with function for displaying calculation results
    By martincrumlish in forum PHP Development
    Replies: 0
    Last Post: October 4th, 2002, 04:34 AM
  4. Same stylesheet for prinitng and displaying?
    By dreamz in forum HTML Programming
    Replies: 4
    Last Post: June 10th, 2002, 06:28 AM
  5. Problem displaying array in checkboxes
    By MarioPro in forum PHP Development
    Replies: 9
    Last Post: May 16th, 2002, 07:19 AM

IMN logo majestic logo threadwatch logo seochat tools logo