can you figure this out

Discussion in 'Programming' started by mumfry, Jun 1, 2010.

  1. #1
    hey yall
    how can i take a number like 120642 and delete all numbers except the last two digits so i end up with 42 .
    i would like to accomplish this task using some kind of php coding
    any ideas
     
    mumfry, Jun 1, 2010 IP
  2. SwedBo

    SwedBo Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo substr("120642", -2);
    PHP:
     
    SwedBo, Jun 1, 2010 IP
  3. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #3
    SwedBo's will give you a string answer with a length of 2 characters always. That means the result for 120602 will be "02". If you want the result to be a number (no leading zeros) use:

    (120602 % 100)

    The result for that will be '2'. In addition the modulus operator (%) will also work in any other situation.

    (120642 % 100) will be 42
     
    plog, Jun 1, 2010 IP
  4. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    wow
    awesome yall
    you guys are the best
    saved me a lot of time

    THANKS
     
    mumfry, Jun 1, 2010 IP
  5. naariel

    naariel Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    ya that will work
     
    naariel, Jun 7, 2010 IP