Results 1 to 2 of 2

Thread: [RESOLVED] How to return integer as its text version (1 = 1st)

  1. #1

    Thread Starter
    Fanatic Member neicedover1982's Avatar
    Join Date
    Jun 2005
    Posts
    566

    Resolved [RESOLVED] How to return integer as its text version (1 = 1st)

    Hello

    I need help. I cant figure out how to write a function to return a integer between 1 and whatever and return it as text like below.

    1 returns 1st
    3 returns 3rd
    28 returns 28th

    any help would be great, thank you
    Kevin | New England Iced Over | http://www.kevincawleyjr.com

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] How to return integer as its text version (1 = 1st)

    Have a go atadapting this function which I found here, unless of course you only need numbers less than 100. Also, if you need this for a date then you can have it added on automatically using the date() function:
    PHP Code:
    <?php
    function nthnum ($age,$small=0) { // proper ending for numbers, ie 2nd, 3rd, 8th
        
    $last_char_age substr("$age", -1);
        switch(
    $last_char_age) {
            case 
    '1' :
                
    $th 'st';
                break;
            case 
    '2' :
                
    $th 'nd';
                break;
            case 
    '3' :
                
    $th 'rd';
                break;
            default :
                
    $th 'th';
                break;
            }
        if (
    $age 10 && $age 20$th 'th';
        if (
    == $small$niceage $age.$th;
        if (
    == $small$niceage $age."<sup>$th</sup>";
        return 
    $niceage;
        }
    ?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width