Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解析Yahoo天气信息的PHP代码因负度数而失败_Php_Parsing_Yahoo - Fatal编程技术网

解析Yahoo天气信息的PHP代码因负度数而失败

解析Yahoo天气信息的PHP代码因负度数而失败,php,parsing,yahoo,Php,Parsing,Yahoo,我有以下代码来解析雅虎天气信息: $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,

我有以下代码来解析雅虎天气信息:

$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;
如何修改解析器以处理负度数


谢谢。

将仪表板设置为可选:

$degreesPattern = '/.*?, (-?\d+) C/i';
                          ^^
从中可以看出,它打印:

-1

这在将codeigniter2.1.4粘贴到视图文件时效果良好

<?php
// weather City qalat-dizah
$xml = simplexml_load_file('http://weather.yahooapis.com/forecastrss?w=1977965&u=c');
    $weatherInfo = $xml->channel->item->description;
    $imagePattern = '/src="(.*?)"/i';
    preg_match($imagePattern, $weatherInfo, $matches);
    $imageSrc = $matches[1];
     echo img($imageSrc) .'<br/>';
    $degreesPattern = '/.*?, (-?\d+) C/i';
    preg_match($degreesPattern, $weatherInfo, $matches);
    $degrees = $matches[1];
  echo  $degrees .'<br/>';
// end
?>
channel->item->description;
$imagePattern='/src=“(.*)”/i';
preg_match($imagePattern,$weatherInfo,$matches);
$imageSrc=$matches[1];
echo img($imageSrc)。“
”; $degreesPattern='/.*?,(?\d+)C/i'; 预匹配($degreesPattern,$weatherInfo,$matches); $degrees=$matches[1]; 回声$degrees.“
”; //结束 ?>