PHP code for parsing Yahoo Weather Info fails for negative degrees
parsing, php, yahoo
Solution
Make the dash optional:
$degreesPattern = '/.*?, (-?\d+) C/i';
^^
You can see from this demo that it prints:
-1
Problem
I have the following code to parse Yahoo Weather Info: ``` $xml = simplexml_load_file('http://weather.yahooapis.com/forecastrss?w=868274&u=c'); $weatherInfo = $xml->channel->item->description; $imagePattern = '/src="(.*?)"/i'; preg_match($imagePattern, $weatherInfo, $matches); $imageSrc = $matches[1]; $degreesPattern = '/.*?, (\d+) C/i'; preg_match($degreesPattern, $weatherInfo, $matches); $degrees = $matches[1]; echo $degrees; ``` How can I modify the parser in order to work for negative degrees? Thank you.