时间:2020-01-18加入收藏
保存为bingpic.php,上传到服务器直接访问即可。<?php
$str=file_get_contents('https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
if (preg_match("/<url>(.+?)<\/url>/ies", $str, $matches)) {
$imgurl='https://cn.bing.com'.$matches[1];
}
if ($imgurl) {
header('Content-Type: image/JPEG');
@ob_end_clean();
@readfile($imgurl);
@flush();
@ob_flush();
exit();
} else {
exit('error');
}
?>
<img src="https://api.bingdou.net/pic/bing/" alt="Bing每日图片" />
tip:修改相关参数即可实现对应的文字说明<?php
$url=file_get_contents('https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
if (preg_match("/<copyright>(.+?)<\/copyright>/ies", $url, $matches)) {
$imgcopyright=$matches[1];
}
if ($imgcopyright) {
header("Content-type: text/html; charset=utf-8");
echo $imgcopyright;
} else {
exit('error');
}
?>
<?php
error_reporting(0);
$path=date('Ym');
if (!file_exists($path)) {
mkdir($path, 0777);
}
$pathurl = $path.'/'.date('d').'.jpg';
if (!is_file($pathurl)) {
$str=file_get_contents('https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
if (preg_match("/<urlBase>(.+?)<\/urlBase>/ies", $str, $matches)) {
$imgurl='https://s.cn.bing.com'.$matches[1].'_1920x1080.jpg';
copy($imgurl, $pathurl);
}
}
header('Content-Type: image/JPEG');
@ob_end_clean();
@readfile($pathurl);
@flush();
@ob_flush();
exit();
?>
TGA: 技巧