Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trimming left side zeros

    Hi

    User may insert numbers as:

    000000000004545498
    00000003585498

    No matter what he types, I need always remove zero from left
    side of variables. (char type)

    Is there a ready function for this, ou how can I do it ?

    Moises

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Why are you using a char type field to store numbers? You should be using one of the number type fields.

    ltrim — Strip whitespace (or other characters) from the beginning of a string
    Code:
    $num = ltrim($num, '0');

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,342
    Thanks
    13
    Thanked 349 Times in 345 Posts
    casting to int should also work.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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