Results 1 to 5 of 5

Thread: Formating Strings

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    philippines
    Posts
    245

    Formating Strings

    How can I format a string from an input value '1' to '01' then typecasting it to string?

    Thanks!

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

    Re: Formating Strings

    I am confused. It would always be a string.
    PHP Code:
    $input 1;

    $input '0' $input// it is a string 
    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.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Formating Strings

    If you want the result to have two digits, even if the input has two digits, you can use sprintf:
    Code:
    $string = sprintf("%02d", $input);
    Note that types aren't very important in PHP.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Formating Strings

    but what if the input has 3 or more?...

    wouldnt it be better to always add a 0 to the input. or if 2 dont add zero. else add a zero
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Formating Strings

    Quote Originally Posted by PlaGuE
    but what if the input has 3 or more?...
    Then the result would still have 3 digits. Field width specifiers never truncate.

    wouldnt it be better to always add a 0 to the input. or if 2 dont add zero. else add a zero
    That would be far more complex, for no gain.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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