您的位置:首页 > 编程语言 > PHP开发

php获取bing每日图片

2014-02-20 17:44 337 查看
必应每天都会更新一些漂亮高清的图片,这段代码获取必应每天更新的图片。我们也可以把它作为网站的背景使用。

必应效果 必应地址:http://cn.bing.com/



实际使用后效果 演示地址:http://cs.dzzoffice.com/



以下代码复制存为 .php文件

代码:

<?php
$str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){
$imgurl='http://cn.bing.com'.$matches[1];
}
if($imgurl){
header('Content-Type: image/JPEG');
@ob_end_clean();
@readfile($imgurl);
@flush(); @ob_flush();
exit();
}else{
exit('error');
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: