1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to stop php from removing Zeros from strings ?

Discussion in 'PHP' started by xkaser101, Jul 23, 2011.

  1. #1
    I am having a trouble when I save integers to my MYSQL database then when I call them in PHP , It instantly trim every Zero in the ending or the beginning of the integer I Have received from the database ?
    Is there anyway to work my way around this ?

    Thanks in advance,
    Kind Regards,
    Issa Shamoun.

    Edit :- I might as well specify that I call the integers into an HTML Text Input not an Echo message Thought this might help
     
    Last edited: Jul 23, 2011
    xkaser101, Jul 23, 2011 IP
  2. suryawl

    suryawl Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    i thought the point of having integer is it behave like a number. if you input 000001.20000000 will be saved 1.2. all integer behave the same way

    if you really want to keep the zero, save it as string or text. hope that helps
     
    suryawl, Jul 23, 2011 IP
    xkaser101 likes this.
  3. xkaser101

    xkaser101 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for sorting this out ! Many Thanks ! :eek:

    So if i want to save phone numbers i have to save it as a string ? and can you explain more about it would a number such as "20" be "2" if i set it as an integer ?

    Edit :- Ops sorry i figured it out =) thanks again
     
    Last edited: Jul 23, 2011
    xkaser101, Jul 23, 2011 IP
  4. suryawl

    suryawl Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #4
    i think 20, 200, 20000 will be saved that way. but integer have their limitation. i don't remember the exact number, but if you must use long number, use big int instead

    php only trims 0.20000000 to 0.2
     
    suryawl, Jul 23, 2011 IP
  5. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    280
    #5
    If it's PHP5 then you can force the variable to be a string using it's cast:

    If it's PHP4, you'd have to use the strval function:

    Or of course, if you are setting the variable absolutely, just put quotes around it:

     
    twistedspikes, Jul 23, 2011 IP
    exodus likes this.
  6. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Yes, phone numbers should be saved as string because they might contain dashes too, not just zero ;)
     
    ads2help, Jul 24, 2011 IP