I am extracting and manipulating data from a Vehicle VIN Decoder. How it works is you enter a vehicle's VIN and it returns data regarding that vehicle's specification.
I am running into some trouble with the engine data. Each data point is tied to an ID, and I extract it using a foreach loop. Engine displacement is tied to $techData[42] where for VIN: WAUUL78E38A092113 $techData[42]= "4.2L/254". I am only concerned with the "4.2L" value. How can I extract just the 4.2L and create a variable with it to then echo? I need this additional code to be flexible and work for any VIN I enter. techData[42] can equal 4.2L, 5L, 5.5L, and on and on. Any ideas regarding how I achieve this would be greatly appreciated. Thanks!
Here is my PHP which returns all the $techData[]:
<?php
$xml = file_get_contents('note.xml');
$dom = new DOMDocument();
$dom->loadXML($xml);
foreach ( $dom->getElementsByTagName('technicalSpecification') as $techSpecElement ) {
foreach($techSpecElement->getElementsByTagName('value') as $valueElement) {
foreach($valueElement->getElementsByTagName('styleId') as $styleIdElement) {
// check the value of the styleId here
if (in_array($styleIdElement->nodeValue, [$variable2])) {
// if it matches, get the parent value element's value
$id = $techSpecElement->getElementsByTagName('titleId')->item(0)->nodeValue;
$techData[$id] = $valueElement->getAttribute("value");
}
}
}
}
echo "<b>Displacement:</b> ".$techData[42]."<br>";
?>
Here is the XML I am pulling this displacement data from:
<technicalSpecification>
<titleId>42</titleId>
<value value="4.2L/254" condition="">
<styleId>292015</styleId>
<styleId>292016</styleId>
</value>
</technicalSpecification>
explode()that variable and use the first value, eg:explode("/",$techData[42])[0]);<titleId>42</titleId>$variable2?