bing每日一图很漂亮,这是今天的每日一图(

PHP代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?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');
}
?>

只有图片,是不是显得太单调了?PHP还可以获取图片版权信息!

1
2
3
4
5
6
7
8
9
10
11
12
13
<?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');
}
?>