美文网首页php基础教程
php天气预报获取小功能

php天气预报获取小功能

作者: 寻梦xunm | 来源:发表于2017-10-03 18:04 被阅读33次

<?php

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

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

//正则表达式

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

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

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

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

}

?>

相关文章

网友评论

    本文标题:php天气预报获取小功能

    本文链接:https://www.haomeiwen.com/subject/bmefyxtx.html