load($xml_db_loc); print $dom; exit; $pressures = $dom->item(0); $doc_contents = file_get_contents($xml_db_loc); } else { $pressures = $dom->appendChild($dom->createElement('pressures')); $doc_contents = ""; } // ----- // Step 2: Get your raw weather data // most people will want to use the url // $weather_data = file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/stations/KSLN.TXT"); // for testing and debugging purposes we can use a local file, too $weather_data = file_get_contents("./KSLN.TXT"); // ----- // Step 3: Figure out the time of the given data into happy fun UNIX epoch form date_default_timezone_set("GMT"); $blammo = explode("\n", $weather_data); $datetime = $blammo[0]; $timestamp = strtotime($datetime); // ----- // Step 3.5: Check if this timestamp has already been done if(preg_match("/" . $timestamp . "/", $doc_contents)) { exit(); } // ----- // Step 4: Figure out what the pressure is $data = $blammo[1]; $data_split = explode(" ", $data); $the_data = false; foreach($data_split as $thingy) { if(preg_match("/^A[0-9][0-9][0-9][0-9]$/", $thingy)) { $the_data = $thingy; } if($the_data) { break; } } $pressure_var = substr($the_data, 1, 4) / 100; // ----- // Step 5: Throw it in the XML file and write $pressure_tag = $dom->appendChild($pressures->createElement('pressure')); $pressure_tag->setAttribute('timestamp', $timestamp); $pressure_tag->setAttribute('pressure', $pressure_var); $dom->formatOutput = true; $dom->save($xml_db_loc); ?>