PHP (number function) help needed.... :(

Discussion in 'PHP' started by ceylongeek, Nov 4, 2010.

  1. #1
    Guys....

    I have an idea to implement a new web solution to our company for that I need your help for some cording supports.

    Guys I have sentential number system like 888881,888882,888883...ect.I need to play with some logic algorithms to extract information from these numbers.I have explain a example below for your ease.

    let's take 888882 here first two digits says the stock number,second two digits says the year,third digit says the color,and last two digits are unique to the situation.Now I need to read the above number and extract those details from that number.For that I need to know a mechanism to check digits alone.


    I mean I need to read the above number and to check
    1.First two digits to find the stock number
    2.Second two digits to find the year
    3.Third digit to find the color....etc


    I have these product numbers in a MySql database and I can get a number to a variable but don't know a way to brake the number to get those details I need your help for this guys.


    If you have a Idea or any tutorial for this situation please help me by posting it here.


    Thank you very much
    Waiting for helps. :)
     
    ceylongeek, Nov 4, 2010 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    $number = "888881";
    
    echo "ID: " . $number . "<br><br>";
    
    $stock = substr($number, 0, 2);
    $year = substr($number, 2, 2);
    $color = substr($number, 4, 1);
    $leftover = substr($number, 5, 1);
    
    echo "Stock: " . $stock . "<br>";
    echo "Year: " . $year . "<br>";
    echo "Color: " . $color . "<br>";
    echo "Unique ID: " . $leftover . "<br>";
    PHP:
    ID: 888881
    
    Stock: 88
    Year: 88
    Color: 8
    Unique ID: 1
    Code (markup):
    Something like this ?
     
    ActiveFrost, Nov 4, 2010 IP
  3. ceylongeek

    ceylongeek Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    Of cause yes ActiveFrost that is what I exactly wanted. :D


    Thank you very much dude.You did a great work.
    Thank you again ActiveFrost
     
    ceylongeek, Nov 4, 2010 IP