Hi there everyone!
As a learning experience, I'm trying to build a VIN(vehicle ident. number) decoder for a enthusiast forum I'm a member of. Basically, I need to break up a supplied VIN into chunks and try to match it to known codes. Due to changing VIN formats over the years, the size and value of the chunks won't remain the same.
To explain better, this link shows what a VIN consists of for 73-79 Ford trucks and this link Shows format for two later year ranges.
So my thinking through my progress so far has been to build arrays for each VIN format that will allow me to provide all the necessary information to check against. The array includes the group, strpos, value and description.
Here's the array I built to match against the 73-79 VIN format:
$match1 = array(
/* Group 1: Vehicle type */
array("group" => "1", "strpos" => "0, 3", "match" => "F10", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "X10", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "F11", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "F14", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "X14", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "F15", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "X15", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "F25", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "X25", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "F26", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "X26", "desc" => "2 Wheel Drive"),
array("group" => "1", "strpos" => "0, 3", "match" => "U15", "desc" => "2 Wheel Drive"),
/* Group 2: Engine */
array("group" => "2", "strpos" => "3, 1", "match" => "A", "desc" => "6Cyl 240 CID 4.0L 1BBL Carburetor 1973-1974"),
array("group" => "2", "strpos" => "3, 1", "match" => "B", "desc" => "6Cyl 300 CID 4.9L 1BBL Carburetor 1973-1979"),
array("group" => "2", "strpos" => "3, 1", "match" => "G", "desc" => "V8 302 CID 5.0L 2BBL Carburetor 1973-1979"),
array("group" => "2", "strpos" => "3, 1", "match" => "H", "desc" => "V8 351M CID 5.8L 2BBL Carburetor 1977-1979"),
array("group" => "2", "strpos" => "3, 1", "match" => "Y", "desc" => "V8 360 CID 5.9L 2BBL Carburetor 1973-1976"),
//array("group" => "2", "strpos" => "3, 1", "match" => "H", "desc" => "V8 390 CID 6.4L 2BBL Carburetor 1973-1976"),
array("group" => "2", "strpos" => "3, 1", "match" => "M", "desc" => "V8 390 CID 6.4L 4BBL Carburetor 1974-1976"),
array("group" => "2", "strpos" => "3, 1", "match" => "S", "desc" => "V8 400 CID 6.6L 2BBL Carburetor 1977-1979"),
array("group" => "2", "strpos" => "3, 1", "match" => "J", "desc" => "V8 460 CID 7.5L 4BBL Carburetor 1973-1979"),
/* Group 3: Assembly Plant */
array("group" => "3", "strpos" => "4, 1", "match" => "B", "desc" => "Oakville, Ontario, Canada"),
array("group" => "3", "strpos" => "4, 1", "match" => "C", "desc" => "Ontario, Canada"),
array("group" => "3", "strpos" => "4, 1", "match" => "E", "desc" => "Mahwah, NJ, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "H", "desc" => "Lorain, OH, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "I", "desc" => "Highland Park, MI, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "K", "desc" => "Kansas City, MO, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "L", "desc" => "Michigan Truck Plant, Wayne, MI, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "N", "desc" => "Norfolk, VA, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "P", "desc" => "Twin Cities, MN, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "R", "desc" => "San Jose, CA, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "S", "desc" => "Allen Park, MI, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "U", "desc" => "Louisville, KY, USA"),
array("group" => "3", "strpos" => "4, 1", "match" => "V", "desc" => "Kentucky Truck Plant, Louisville, KY, USA")
);
This allows me to build an array for every VIN format under the sun, but I need a way to loop through all the chunks or groups of information, check for a match and if found, move to next group, in VIN array until you run out of groups to check. If you've made it through all groups without lacking a match in any group, You've found your VIN format. If you didn't find matches for every group, you need to move on to the next VIN format array.
Here's the code I've written so far for this, but I didn't make it far before I was stymied:
$_POST['vin'] = "U15HLEA2601";
if(ISSET($_POST['vin'])){
$vin = $_POST['vin'];
/* Letters and numbers only */
if(!ctype_alnum($vin)) {
$result = "Hey, buddy! your VIN will only have letters and numbers! Try it again.";
}elseif(strlen($vin) > 17){
$result = "My, what a big VIN you have... In fact, it's too big. Someone's compensating.";
}else{
/* Basic checks have passed. Let's see if we can decode it. */
$mc = 1;
/* This will loop through all VIN arrays until we either run out or a match is found */
while (ISSET(${'match'.$mc}) AND !ISSET($matchfound)){ // This loops through each VIN format array and will stop if we define $matchfound in the previous array.
foreach(${'match'.$mc} AS $match){
// Things that need to happen here:
// Looping through this $match, it should find a match
// in group 1 before moving to group 2. If no match
// was found before moving to the next group, we know
// that this is NOT the right VIN format, so we can move
// onto the next $match(num) right away.
//
// If we do make it through each group in this array and
// find a match for each, we need to define $matchfound
// and quit this loop.
}
$mc = ++$mc;
}
exit;
$result = "We know a little sumfin sumfin about that VIN:";
}
}
I just can't quite figure out how to make this loop through each group, determine match status and decide whether to move on to next group or stop and move to next array if it exists.
If anyone has an idea of how I would handle this, it would be greatly appreciated and if I've confused anyone or missed the mark on providing data, just let me know.
Thanks for your time!