
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 2.51 KB | hits: 26 | expires: Never
<?php
error_reporting(E_ALL);
$cars = getCarsDB();
$mk = 1;
$mdl = 2;
$yr = 3;
$i = 1;
foreach ($cars as $make => $value)
{
if($make == 'BMW' || $make == 'Mercedes-Benz' || $make == 'Audi' || $make == 'Porsche' || $make == 'Volkswagen')
{
$mk = $i;
echo "INSERT INTO drupal_term_data (vid,name,description) VALUES ('2','$make', '$make');
";
echo "INSERT INTO drupal_term_hierarchy (tid,parent) VALUES ('" . $i++ . "','0');
";
//$mk++;
}
else
{
continue;
}
foreach ($value as $model => $value1)
{
$mdl = $i;
echo "INSERT INTO drupal_term_data (vid,name,description) VALUES ('2','$model', '$model');
";
echo "INSERT INTO drupal_term_hierarchy (tid,parent) VALUES ('" . $i++ . "','" . $mk . "');
";
foreach ($value1 as $year)
{
echo "INSERT INTO drupal_term_data (vid,name,description) VALUES ('2','$year', '$year');
";
echo "INSERT INTO drupal_term_hierarchy (tid,parent) VALUES ('" . $i++ . "','" . $mdl . "');
";
}
$mdl++;
}
$mk++;
}
function getCarsDB()
{
$file = file_get_contents('http://scripts.kbb.com/kbb/ymmData.axd?VehicleClass=UsedCar');
$file = explode("\n",$file);
$patternMake = '/ymUsed_\[\d{4}\]\s*=\s*\'([^\']+)\'/';
$patternModel = '/ymmUsed_\["(\d+)~(\d+)"\]\s*=\s*"([^"]+)"/';
foreach($file as $row)
{
if(preg_match($patternMake,$row,$matched))
{
$tmpMakes = explode(',',$matched[1]);
foreach($tmpMakes as $str)
{
list($id,$name) = explode("|",$str);
$arrMakes[$id] = $name;
}
}
unset($str);
if(preg_match($patternModel,$row,$matched))
{
$year = $matched[1];
$make_id = $matched[2];
$models = $matched[3];
$tmpModels = explode(',',$models);
foreach($tmpModels as $str)
{
list($id,$model_name) = explode("|",$str);
$make_name = $arrMakes[$make_id];
$arrModels[$make_name][$model_name][$year] = $year;
}
}
}
ksort($arrModels);
foreach ($arrModels as &$make)
{
ksort($make);
foreach ($make as &$model)
ksort($model);
}
return $arrModels;
}