建站之天气获取
写文章时自动抓取当前天气,找了几个 api 都不靠谱,直接采集中国天气网的数据。
例如采集富阳的天气地址:
$url = 'http://www.weather.com.cn/weather/101210108.shtml';$raw = file_get_contents($url);$raw = str_replace("\n", '', $raw);if (preg_match('<input type="hidden" id="hidden_title" value="(.+?)" \/>', $raw, $match)) { //匹配到天气文字}
标签:建站