SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: 7 to 07

  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    7 to 07

    Hello,

    I'm running a script that intake 07 as valid number not 7.
    How can I convert 7 to 07.

    Thanks In advance,

    Regards,
    Kevin

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    $variable = "0$variable";

  3. #3
    SitePoint Enthusiast toytron's Avatar
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe this post about adding zero's could also help.

  4. #4
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can also use

    $number_formatted=sprintf("%02d",$variable );

    sprintf return the formatted string.

  5. #5
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Please let me know "%02d" stands for ?

    Regards,
    NewBizz


    Quote Originally Posted by priti View Post
    you can also use

    $number_formatted=sprintf("%02d",$variable );

    sprintf return the formatted string.

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newbizz View Post
    Hello,

    Please let me know "%02d" stands for ?

    Regards,
    NewBizz
    http://www.php.net/manual/en/function.sprintf.php
    Look at example 7.

    It adds zeroes in front of the variable, until it's at least two characters long. So '7' will become '07', and '07' would remain '07'.


Bookmarks

Posting Permissions

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