Separate XML Attributes In PHP
I'm getting the XML attributes for sky_condition from this XML file:
Solution 1:
Just do this
$xmlString = '<METAR>
<sky_condition sky_cover="SCT" cloud_base_ft_agl="1600"/>
<sky_condition sky_cover="BKN" cloud_base_ft_agl="2200"/>
</METAR>
';
$xml = simplexml_load_string($xmlString);
$td = "<tr><td><strong>%s</strong></td><td><strong>%s</strong></td></tr>";
echo '<table>';
foreach ( $xml->sky_condition as $value ) {
$attribute = $value->attributes();
printf($td, $attribute['sky_cover'], $attribute['cloud_base_ft_agl']);
}
echo '</table>';
See Demo
Post a Comment for "Separate XML Attributes In PHP"