SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    bahrain
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up how to get rid of leading zeros???

    hi
    i have several numbers which i want to store in database. but problem is that a lot of having leading zeros (zeros i the beginning) e.g 00025683 , 0025474 , 0584026 , 00000574560 etc

    now i want to get rid of these leading zeros and store on;y the real number means if it is 000257060 i want it like this 257060.how to do this????
    its urgent plzzz.....
    regards
    phphelp

  2. #2
    SitePoint Zealot joazito's Avatar
    Join Date
    Mar 2005
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (my first post)

    Well you could try intval():
    PHP Code:
    $number_without_zeros intval($original_number); 
    Note that this only works if $original_number is an integer.
    Another thing... if the field you're inserting in the database is of integer type, those leading zeros wouldn't be stored in the database.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    K.S.A
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if the field you're inserting in the database is of integer type, those leading zeros wouldn't be stored in the database.
    there is an option in MySQL which is UNSIGNED_ZEROFILL..
    as for casting, also this will work:
    PHP Code:
     $number_without_zeros = (int) $original_number

  4. #4
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    bahrain
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx joazito and NeverMind and best of luck joazito as u have posted ur first post.
    its urgent plzzz.....
    regards
    phphelp


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
  •