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.
Make the dash optional:
You can see from this demo that it prints: