Last active
August 29, 2015 13:58
-
-
Save jmsaavedra/9985683 to your computer and use it in GitHub Desktop.
PHP simpleXML example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//first grab the xml file | |
$xml=simplexml_load_file("http://www.stateair.net/web/rss/1/1.xml"); | |
/* simpleXML let's you parse through the entire file */ | |
/* info: http://www.w3schools.com/php/php_xml_simplexml.asp */ | |
//foreach($xml->children() as $child) { | |
// echo $child->getName() . ": " . $child . "<br>"; | |
//} | |
/*this line will print out the value by itself to the browser: */ | |
//echo "current AQI value: " . $xml->channel[0]->item[0]->AQI; | |
/* we let the arduino know that a message has arrived by starting | |
the value with a '#' and ending it with a '!'. So, whatever we want | |
the arduino to receive, we wrap with those characters. */ | |
//test setup: | |
$testValue = 15; //test variable | |
echo "#" . $testValue . "!"; //echo out the test variable | |
//this is returning the FIRST ITEM'S AQI (uncomment) | |
//echo "#" . $xml->channel[0]->item[0]->AQI . "!"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment