Jump to content

printing a value from a xml file


snowscar

Recommended Posts

I am trying to print some value from an xml file. I am sorry but I dont knw much of php and I really need help.

the xml file is http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=RPVI

 

This is the code i have so far but none of it seems to work.

I just want it to display some items like city, wind direction, speed,etc.

 

How can I do this ?

 

 

<?php

if(!$xml=simplexml_load_file('http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=RPVI')){

    trigger_error('Error reading XML file',E_USER_ERROR);

}

 

//Trying to print the credit name

print $xml->current_observation->credit . "\n";

 

//Trying another way to print it

foreach ($xml->items as $item) {

        $city = $item['city'];

        $desc = $item['description'];

        echo "<b>".$city."</b><br>";

        if($desc) echo $desc."<br>";

 

}?>

Link to comment
https://forums.phpfreaks.com/topic/122134-printing-a-value-from-a-xml-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.