3v4l.org

run code in 300+ PHP versions simultaneously
<?php function searchByVINs ($VINs,$fields) { /* // test multi-VIN batching via textarea at bottom of https://vpic.nhtsa.dot.gov/api/ $stream_options_content = http_build_query(["data" => implode(";", $VINS), "format" => "JSON"]); $stream_options = [ 'http' => [ 'header' => "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: ".strlen($postdata)."\r\n", 'method' => "POST", 'content' => $postdata ] ]; $context = stream_context_create($stream_options); $apiURL = "https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/"; if (!$fp = @fopen($apiURL, "rb", FALSE, $context)) { return ["success" => false, "response" => "Unable to open stream"]; } if (!$response = stream_get_contents($fp),true)) { return ["success" => false, "response" => "Unable to receive streamed data"]; } */ $response = '{"Count":2,"Message":"Results returned successfully","SearchCriteria":"","Results":[{"ABS":"","AEB":"","AdaptiveCruiseControl":"","AdaptiveHeadlights":"","AdditionalErrorText":"","AirBagLocCurtain":"","AirBagLocFront":"","AirBagLocKnee":"","AirBagLocSeatCushion":"","AirBagLocSide":"","Artemis":"","AxleConfiguration":"","Axles":"","BasePrice":"","BatteryA":"","BatteryA_to":"","BatteryCells":"","BatteryInfo":"","BatteryKWh":"","BatteryKWh_to":"","BatteryModules":"","BatteryPacks":"","BatteryType":"","BatteryV":"","BatteryV_to":"","BedLengthIN":"","BedType":"","BlindSpotMon":"","BodyCabType":"","BodyClass":"Wagon","BrakeSystemDesc":"","BrakeSystemType":"Hydraulic","BusFloorConfigType":"","BusLength":"","BusType":"","CAFEBodyType":"","CAFEMake":"","CAFEModel":"","CashForClunkers":"","ChargerLevel":"","ChargerPowerKW":"","CoolingType":"","Country":"","CurbWeightLB":"","CustomMotorcycleType":"","DestinationMarket":"","DisplacementCC":"2200.0","DisplacementCI":"134.25223700841","DisplacementL":"2.2","Doors":"4","DriveType":"","DriverAssist":"","ESC":"","EVDriveUnit":"","ElectrificationLevel":"","EngineConfiguration":"","EngineCycles":"","EngineCylinders":"4","EngineHP":"","EngineHP_to":"","EngineKW":"","EngineManufacturer":"GM","EngineModel":"L61\/LBZ","EntertainmentSystem":"","EquipmentType":"","ErrorCode":"1 - VIN decoded clean. Check Digit (9th position) does not calculate properly.","ForwardCollisionWarning":"","FuelInjectionType":"Multipoint Fuel Injection (MPFI)","FuelTypePrimary":"Gasoline","FuelTypeSecondary":"","GVWR":"Class 1D: 5,001 - 6,000 lb (2,268 - 2,722 kg)","LaneDepartureWarning":"","LaneKeepSystem":"","Make":"CHEVROLET","Manufacturer":"GENERAL MOTORS LLC","ManufacturerId":"984","ManufacturerType":"","Model":"HHR","ModelYear":"2006","MotorcycleChassisType":"","MotorcycleSuspensionType":"","NCAPBodyType":"","NCAPMake":"","NCAPModel":"","NCICCode":"","NCSABodyType":"","NCSAMake":"","NCSAModel":"","Note":"","OtherBusInfo":"","OtherEngineInfo":"L61: 2.2L, 4Cyl, Aluminium, DOHC MFI\u000d\u000aLBZ: 6.6L, V8, DI, Turbo Diesel, inc HP","OtherMotorcycleInfo":"","OtherRestraintSystemInfo":"","OtherTrailerInfo":"","ParkAssist":"","PlantCity":"Ramos Arizpe","PlantCompanyName":"GMNA","PlantCountry":"Mexico","PlantState":"","PossibleValues":"","Pretensioner":"","RearVisibilityCamera":"","SeatBeltsAll":"","SeatRows":"","Seats":"","Series":"LS","Series2":"","SteeringLocation":"","SuggestedVIN":"","TPMS":"","TopSpeedMPH":"","TrackWidth":"","TractionControl":"","TrailerBodyType":"","TrailerLength":"","TrailerType":"","TransmissionSpeeds":"","TransmissionStyle":"","Trim":"1\/2 Ton","Trim2":"","Turbo":"","VIN":"3GNDA13D76S000000","ValveTrainDesign":"Dual Overhead Cam (DOHC)","VehicleType":"MULTIPURPOSE PASSENGER VEHICLE (MPV)","WheelBaseLong":"","WheelBaseShort":"","WheelBaseType":"","WheelSizeFront":"","WheelSizeRear":"","Wheels":"","Windows":""},{"ABS":"","AEB":"","AdaptiveCruiseControl":"","AdaptiveHeadlights":"","AdditionalErrorText":"","AirBagLocCurtain":"1st & 2nd Rows","AirBagLocFront":"1st Row (Driver & Passenger)","AirBagLocKnee":"","AirBagLocSeatCushion":"","AirBagLocSide":"1st Row (Driver & Passenger)","Artemis":"","AxleConfiguration":"","Axles":"","BasePrice":"","BatteryA":"","BatteryA_to":"","BatteryCells":"","BatteryInfo":"","BatteryKWh":"","BatteryKWh_to":"","BatteryModules":"","BatteryPacks":"","BatteryType":"","BatteryV":"","BatteryV_to":"","BedLengthIN":"","BedType":"","BlindSpotMon":"","BodyCabType":"","BodyClass":"Wagon","BrakeSystemDesc":"","BrakeSystemType":"","BusFloorConfigType":"","BusLength":"","BusType":"","CAFEBodyType":"","CAFEMake":"","CAFEModel":"","CashForClunkers":"","ChargerLevel":"","ChargerPowerKW":"","CoolingType":"","Country":"","CurbWeightLB":"","CustomMotorcycleType":"","DestinationMarket":"","DisplacementCC":"2400.0","DisplacementCI":"146.45698582735","DisplacementL":"2.4","Doors":"","DriveType":"4x2","DriverAssist":"","ESC":"","EVDriveUnit":"","ElectrificationLevel":"","EngineConfiguration":"","EngineCycles":"","EngineCylinders":"","EngineHP":"","EngineHP_to":"","EngineKW":"","EngineManufacturer":"","EngineModel":"DOHC MPI THETA-II","EntertainmentSystem":"","EquipmentType":"","ErrorCode":"1 - VIN decoded clean. Check Digit (9th position) does not calculate properly.","ForwardCollisionWarning":"","FuelInjectionType":"Multipoint Fuel Injection (MPFI)","FuelTypePrimary":"Gasoline","FuelTypeSecondary":"","GVWR":"Class 1C: 4,001 - 5,000 lb (1,814 - 2,268 kg)","LaneDepartureWarning":"","LaneKeepSystem":"","Make":"KIA","Manufacturer":"HYUNDAI-KIA AMERICA TECHNICAL CENTER INC (HATCI)","ManufacturerId":"1034","ManufacturerType":"","Model":"Sorento","ModelYear":"2012","MotorcycleChassisType":"","MotorcycleSuspensionType":"","NCAPBodyType":"","NCAPMake":"","NCAPModel":"","NCICCode":"","NCSABodyType":"","NCSAMake":"","NCSAModel":"","Note":"","OtherBusInfo":"","OtherEngineInfo":"","OtherMotorcycleInfo":"","OtherRestraintSystemInfo":"","OtherTrailerInfo":"","ParkAssist":"","PlantCity":"","PlantCompanyName":"Kia Motor Manufacturing, Georgia","PlantCountry":"United States (USA)","PlantState":"Georgia","PossibleValues":"","Pretensioner":"","RearVisibilityCamera":"","SeatBeltsAll":"Manual","SeatRows":"","Seats":"","Series":"GL(Middle-low grade)","Series2":"","SteeringLocation":"","SuggestedVIN":"","TPMS":"Direct","TopSpeedMPH":"","TrackWidth":"","TractionControl":"","TrailerBodyType":"","TrailerLength":"","TrailerType":"","TransmissionSpeeds":"","TransmissionStyle":"","Trim":"","Trim2":"","Turbo":"","VIN":"5XYKT3A12CG000000","ValveTrainDesign":"Dual Overhead Cam (DOHC)","VehicleType":"MULTIPURPOSE PASSENGER VEHICLE (MPV)","WheelBaseLong":"","WheelBaseShort":"","WheelBaseType":"","WheelSizeFront":"","WheelSizeRear":"","Wheels":"","Windows":""}]}'; if(($data = @json_decode($response,true)) === null && json_last_error()!==JSON_ERROR_NONE){ return ["success" => false, "response" => "Unable to parse streamed data"]; } if (!isset($data["Message"]) || $data["Message"] != "Results returned successfully") { return ["success" => false, "response" => "Received unsuccessful dataset"]; } $return = []; $keys = array_flip($fields); foreach ($data["Results"] as $dataset) { $isolated = array_intersect_key($dataset,$keys); // only retain the elements with keys that match $fields values $sorted = array_replace($keys,$isolated); // order the dataset by order of elements in $fields $return[] = $sorted; } return ["success" => true, "response" => $return]; } $VINs = ["3GNDA13D76S000000", "5XYKT3A12CG000000"]; $fields = ["VIN", "ModelYear", "Make", "FuelTypePrimary", "DriveType", "BodyClass"]; $response = searchByVINs($VINs,$fields); if (!$response["success"]) { echo "Oops, the api call failed. {$response["response"]}"; } else { foreach ($response["response"] as $item){ echo "<div>\n"; foreach ($item as $key => $value) { echo "\t<div>$key: $value</div>\n"; } echo "</div>\n"; } }
Output for git.master, git.master_jit, rfc.property-hooks
<div> <div>VIN: 3GNDA13D76S000000</div> <div>ModelYear: 2006</div> <div>Make: CHEVROLET</div> <div>FuelTypePrimary: Gasoline</div> <div>DriveType: </div> <div>BodyClass: Wagon</div> </div> <div> <div>VIN: 5XYKT3A12CG000000</div> <div>ModelYear: 2012</div> <div>Make: KIA</div> <div>FuelTypePrimary: Gasoline</div> <div>DriveType: 4x2</div> <div>BodyClass: Wagon</div> </div>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
109.7 ms | 406 KiB | 5 Q