php天气预报获取小功能

//获取天气预报网站的网页内容

$html = file_get_contents("http://www.weather.com.cn/weather1d/101210101.shtml");

//正则表达式

$reg = '#hour3data.+?\[".+?,.+?,(?.+?),(?.+?),#';

//如果匹配成功,就输出温度相关的信息

if(preg_match($reg, $html, $mat)){

    echo "今天".$mat['tianqi'].",温度".$mat['wendu'];

}

?>

你可能感兴趣的:(php天气预报获取小功能)