Skip to content

Instantly share code, notes, and snippets.

@heartnn
Last active March 2, 2018 14:34
Show Gist options
  • Save heartnn/43cbeb21bd5d76ed79add4b454c4ae93 to your computer and use it in GitHub Desktop.
Save heartnn/43cbeb21bd5d76ed79add4b454c4ae93 to your computer and use it in GitHub Desktop.
php-bing-wallpaper
<?php
/*提取Bing网站的信息*/
$str=file_get_contents('https://www.bing.com/HPImageArchive.aspx?idx=0&n=1');
/*匹配字符串中的url超链接,成功返回 1 ,否则返回 0 */
if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){
$imgurl='http://www.bing.com'.$matches[1];
}
if($imgurl){
/*用于发送原生的 HTTP 头,提示输出图片*/
header('Content-Type: image/JPEG');
/*清空(擦除)缓冲区并关闭输出缓冲*/
@ob_end_clean();
/*读取文件并写入到输出缓冲 */
@readfile($imgurl);
/*该函数将当前为止程序的所有输出发送到用户的浏览器*/
@flush();
/*这个函数将送出缓冲区的内容(如果里边有内容的话)*/
@ob_flush();
exit();
}else{
exit('error');
}
?>
<?php
header('Access-Control-Allow-Origin: *');
header('Content-type:image/jpg');
error_reporting(0);
ob_end_clean();
ob_start();
$OBingJson=file_get_contents('https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
$BingJson=json_decode($OBingJson,true);
/*遍历数组*/
foreach($BingJson as $key=>$val){
$picUrl='http://www.bing.com'.$BingJson['images'][0]['url'];
$iurl=readfile($picUrl);
$in=ob_get_contents($iurl);
return $in;
exit();
};
?>
<?php
error_reporting(0);
$OBingJson=file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
$BingJson=json_decode($OBingJson,true);
$picUrl="https://cn.bing.com".$BingJson['images'][0]['url'];
header("Location:".$picUrl);
?>
<?php
$str = file_get_contents('https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
$data = json_decode($str);
$imgurl = "https://www.bing.com".$data -> {"images"}[0] -> {"url"};
if($imgurl){
$img = imagecreatefromjpeg($imgurl);
header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime(date('Y-m-d', strtotime('+1 day')))) . ' GMT');
header('Cache-Control: public, max-age=3600');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', strtotime(date('Y-m-d'))) . ' GMT');
header('Content-Type: image/jpeg');
imageinterlace($img, 1);
imagejpeg($img);
imagedestroy($img);
exit();
}else{
exit('error');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment