如题,求一个能将远程网页保存到自己的虚拟主机服务器并可以自动重新添加进内容的PHP源码。
要保存的网页在http://m.weather.com.cn/data/101120301.html
目标网页的内容是
###################################################################################################
{"weatherinfo":{"city":"淄博","city_en":"zibo","date_y":"2010年7月7日","date":"庚寅年五月廿六","week":"星期三","fchh":"08","cityid":"101120301","temp1":"37℃~25℃","temp2":"35℃~24℃","temp3":"32℃~22℃","temp4":"29℃~21℃","temp5":"31℃~21℃","temp6":"34℃~22℃","tempF1":"98.6℉~77℉","tempF2":"95℉~75.2℉","tempF3":"89.6℉~71.6℉","tempF4":"84.2℉~69.8℉","tempF5":"87.8℉~69.8℉","tempF6":"93.2℉~71.6℉","weather1":"晴转多云","weather2":"多云","weather3":"雷阵雨","weather4":"雷阵雨转多云","weather5":"多云转晴","weather6":"晴","img1":"0","img2":"1","img3":"1","img4":"99","img5":"4","img6":"99","img7":"4","img8":"1","img9":"1","img10":"0","img11":"0","img12":"99","img_single":"0","img_title1":"晴","img_title2":"多云","img_title3":"多云","img_title4":"多云","img_title5":"雷阵雨","img_title6":"雷阵雨","img_title7":"雷阵雨","img_title8":"多云","img_title9":"多云","img_title10":"晴","img_title11":"晴","img_title12":"晴","img_title_single":"晴","wind1":"南风小于3级","wind2":"南风小于3级","wind3":"北风小于3级","wind4":"北风小于3级","wind5":"北风小于3级","wind6":"北风转南风小于3级","fx1":"南风","fx2":"南风","fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"炎热","index_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index48":"炎热","index48_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index_uv":"强","index48_uv":"中等","index_xc":"较适宜","index_tr":"较不宜","index_co":"很不舒适","st1":"37","st2":"25","st3":"35","st4":"24","st5":"30","st6":"20","index_cl":"适宜","index_ls":"极适宜"}}
#######################################################################################
要求可以保存为本地的html文件。如1.html 并且在里面加入 类似于 "tianqi":"天气"这样的字段。
做PHP版的免费飞信天气预报用!
要保存的网页在http://m.weather.com.cn/data/101120301.html
目标网页的内容是
###################################################################################################
{"weatherinfo":{"city":"淄博","city_en":"zibo","date_y":"2010年7月7日","date":"庚寅年五月廿六","week":"星期三","fchh":"08","cityid":"101120301","temp1":"37℃~25℃","temp2":"35℃~24℃","temp3":"32℃~22℃","temp4":"29℃~21℃","temp5":"31℃~21℃","temp6":"34℃~22℃","tempF1":"98.6℉~77℉","tempF2":"95℉~75.2℉","tempF3":"89.6℉~71.6℉","tempF4":"84.2℉~69.8℉","tempF5":"87.8℉~69.8℉","tempF6":"93.2℉~71.6℉","weather1":"晴转多云","weather2":"多云","weather3":"雷阵雨","weather4":"雷阵雨转多云","weather5":"多云转晴","weather6":"晴","img1":"0","img2":"1","img3":"1","img4":"99","img5":"4","img6":"99","img7":"4","img8":"1","img9":"1","img10":"0","img11":"0","img12":"99","img_single":"0","img_title1":"晴","img_title2":"多云","img_title3":"多云","img_title4":"多云","img_title5":"雷阵雨","img_title6":"雷阵雨","img_title7":"雷阵雨","img_title8":"多云","img_title9":"多云","img_title10":"晴","img_title11":"晴","img_title12":"晴","img_title_single":"晴","wind1":"南风小于3级","wind2":"南风小于3级","wind3":"北风小于3级","wind4":"北风小于3级","wind5":"北风小于3级","wind6":"北风转南风小于3级","fx1":"南风","fx2":"南风","fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"炎热","index_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index48":"炎热","index48_d":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。","index_uv":"强","index48_uv":"中等","index_xc":"较适宜","index_tr":"较不宜","index_co":"很不舒适","st1":"37","st2":"25","st3":"35","st4":"24","st5":"30","st6":"20","index_cl":"适宜","index_ls":"极适宜"}}
#######################################################################################
要求可以保存为本地的html文件。如1.html 并且在里面加入 类似于 "tianqi":"天气"这样的字段。
做PHP版的免费飞信天气预报用!
如果要往里面+东西可以用正则!
这个对于有的来说是不行的哦~一个比较完整的函数gethttpcnt ,通过CURL来获取HTML文件内容://获取远程网址的内容,采用curl,一般用于外站的内容获取
function gethttpcnt($url,$username = '',$password = '',$timeout = 5){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //在需要用户检测的网页里需要增加下面两行
if($username && $password){
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
}
$cnt = curl_exec($ch);
curl_close($ch);
return $cnt;
}
http://topic.csdn.net/u/20100706/14/dd3bd6a1-576a-46b9-a127-dabea8bb89d8.html (#35楼)
参照PHP手册中cURL的说明,自己动手做一下,才能发现问题,别人才能帮你具体解决。