Skip to content

Instantly share code, notes, and snippets.

@jmsaavedra
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmsaavedra/9985683 to your computer and use it in GitHub Desktop.
Save jmsaavedra/9985683 to your computer and use it in GitHub Desktop.
PHP simpleXML example
<?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