- array_map: documentation ( source)
- file_get_contents: documentation ( source)
- var_dump: documentation ( source)
- json_decode: documentation ( source)
- in_array: documentation ( source)
- strtolower: documentation ( source)
<?php
function vinHasRecallCode($vin, $code) {
$json = file_get_contents("http://www.vw.com/s2f/vwrecall-nhtsa2/vin/$vin");
if (!$json) {
throw new Exception('Error contacting API server.');
}
$data = json_decode($json);
if (!($data instanceof stdClass)) {
throw new Exception('Malformed JSON data.');
}
if (!is_array($data->recalls)) {
throw new Exception('Malformed JSON schema.');
}
if (empty($data->recalls)) {
return false;
}
return in_array(strtolower($code), array_map('strtolower', $data->recalls));
}
var_dump(vinHasRecallCode('3VWTL81K29M344780', '23Q2'));