calivw78 Posted December 5, 2009 Share Posted December 5, 2009 Hello all, I am currently working with some code that I found online to query the temperature from wunderground.com. The problem that I am running into, is that the code does not appear to allow negative values. Actually, I think it is simply not allowing the "-" to appear before the number. I am not very fluent in php, but am reading plenty of resources. None of those have helped me out yet though and my messing around with with the "value=" section of the below code has not resulted in the desired results. Anyone have some thoughts? Here is what I am currently using: if (preg_match('#pwsvariable="tempf" english="°F" metric="°C" value="([0-9\.]+)">#', $page, $matches)) { $current_temp = $matches[1]; Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/184053-allowing-both-positive-and-negative-values-from-query/ Share on other sites More sharing options...
calivw78 Posted December 5, 2009 Author Share Posted December 5, 2009 For future reference, I fixed it by adjusting the code in my initial post to use value="(-?[0-9\.]+)" This allowed the negative character to be displayed. In the end though, I found an easier way to get the values via XML #!/usr/bin/php #query weather data from wunderground xml for use with mrtg / rrdtool graphing utilities <?php //Get the XML document loaded into a variable $ch = curl_init("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=80013"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $url = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($url); echo $xml->temp_f."\n"; echo $xml->windchill_f."\n"; ?> Link to comment https://forums.phpfreaks.com/topic/184053-allowing-both-positive-and-negative-values-from-query/#findComment-971838 Share on other sites More sharing options...
calivw78 Posted December 5, 2009 Author Share Posted December 5, 2009 Oh, and the XML parsing didn't want to play nice until I upgraded from PHP version 5.2.4-1 to 5.2.11-1 Link to comment https://forums.phpfreaks.com/topic/184053-allowing-both-positive-and-negative-values-from-query/#findComment-971850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.