0x-1
这破主题太难整PJAX,我整了一周毫无作用,身为一个小白的我心好累
0x01
<?php
if($_GET['idx']==null){
$_GET['idx']=0;
}
if($_GET['w']==null){
$_GET['w']='1366x768';
}
function bingImgFetch(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.bing.com/HPImageArchive.aspx?format=js&idx='.$_GET['idx'].'&n=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$re = curl_exec($ch);
curl_close($ch);
$re = json_decode($re,1);//电脑版返回内容
return array(
/* 更改图片尺寸,减小体积 */
'url' => str_replace('1920x1080',$_GET['w'],$re['images'][0]['url']),
);
}
$bingimg= bingImgFetch();
$imgurl='https://upyun-bing.woshiluo.dream.ren'.$bingimg['url'];
$url = $imgurl;
Header("Location:$url");
?>
为了统一格式储存进去必须得是统一分辨率,我直接选则1920×1080,因为这个时默认获取值,当然我们不可能再替换一次,所以直接在输出时再增加一个值,就用$re['images'][0]['url']
来输出,函数部分就成了这样
function bingImgFetch(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.bing.com/HPImageArchive.aspx?format=js&mkt=zh-cn&idx='.$_GET['idx'].'&n=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$re = curl_exec($ch);
curl_close($ch);
$re = json_decode($re,1);
return array(
'url' => str_replace('1920x1080',$_GET['w'],$re['images'][0]['url']),
'imgurl' => $re['images'][0]['url']
);
}
0x02
在结尾增加输出地址,写入部分做出以下更改揪心
$myfile = fopen("./bing.txt", "a") or die("Unable to open file!");
$all ="<date>".$time."</date>n"."<match id=".$time.">".$match['0']."</match>n"."<url id=".$time.">".$bingimg['imgurl']."</url>n"."<hpla id=".$time.">".$bing['hpla']."</hpla>n"."<add id=".$time.">".$bing['add']."</add>n"."<title id=".$time.">".$bing['title']."</title>n"."<titles id=".$time.">".$bing['titles']."</titles>n"."<more id=".$time.">".$bing['more']."</more>n";
fwrite($myfile, $all);
fclose($myfile);
<match>
是指到这张图片为止所获取的图片数量
1×01
你觉得都用HTML标签了获取的方法和判断的方法还需要多说吗?直接上代码
<?php
date_default_timezone_set (PRC);#定义时区,我只是担心时区出错导致获取偏差
if($_GET['idx']==null){
$_GET['idx']=0;#没有定义天数则默认为0
}
if($_GET['w']==null){
$_GET['w']='1366x768';#没有定义长与宽,则默认设为1366x768
}
$time= date("20ymd",strtotime('-'.$_GET['idx'].'day'));
$time1= date("20ymd",strtotime('-1 day'));
$text2=file_get_contents('./bing.txt');
if(preg_match('/[<]+date[>]+'.$time.'/',$text2))
{
preg_match('$(?<=<matchsid='.$time1.'>)(.*?)(?=</match>)$',$text2,$match);#获取总量
if($match > $idx){#判断是否在可以获取范围内
preg_match('$(?<=<urlsid='.$time.'>)(.*?)(?=</url>)$',$text2,$url);
$bing['url']=$url[0];
$url=str_replace('1920x1080',$_GET['w'],$bing['url']);
$imgurl='https://cn.bing.com'.$url;
Header("Location:$imgurl");
}
}
else{
preg_match('$(?<=<matchsid='.$time1.'>)(.*?)(?=</match>)$',$text2,$match);#因为已经获取清楚了之前的,所以这个必然是今天的,用这一段来获取从开始到昨天的所有以被获取的次数
if($match['0'] < 8){
$match['0']=8;#因为官方至少可以获取8天,所以这个值不可能小于8
}
else{
$match['0']=$match['0']+1;#大于8加以一
}
if($match-1 > $idx){#判断是否在可以获取范围内
$text=file_get_contents('http://cn.bing.com/cnhp/life?currentDate='.$time);
preg_match('$(?<=<divsclass="hplatt">)(.*?)(?=</div>)$',$text,$title);
$bing['title']=$title[0];
preg_match('$(?<=<spansclass="hplaAttr">)(.*?)(?=</span>)$',$text,$add);
$bing['add']=$add[0];
preg_match('$(?<=<divsclass="hplats">)(.*?)(?=</div>)$',$text,$titles);
$bing['titles']=$titles[0];
preg_match('$(?<=<divsclass="hplaTtl">)(.*?)(?=</div>)$',$text,$hpla);
$bing['hpla']=$hpla[0];
preg_match('$(?<=<divsid="hplaSnippet">)(.*?)(?=</div>)$',$text,$more);
$bing['more']=$more[0];
function bingImgFetch(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.bing.com/HPImageArchive.aspx?format=js&mkt=zh-cn&idx='.$_GET['idx'].'&n=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$re = curl_exec($ch);
curl_close($ch);
$re = json_decode($re,1);
return array(
'url' => str_replace('1920x1080',$_GET['w'],$re['images'][0]['url']),
'imgurl' => $re['images'][0]['url']
);
}
$bingimg= bingImgFetch();
$imgurl='https://cn.bing.com'.$bingimg['url'];
$url = $imgurl;
$myfile = fopen("./bing.txt", "a") or die("Unable to open file!");
$all ="<date>".$time."</date>n"."<match id=".$time.">".$match['0']."</match>n"."<url id=".$time.">".$bingimg['imgurl']."</url>n"."<hpla id=".$time.">".$bing['hpla']."</hpla>n"."<add id=".$time.">".$bing['add']."</add>n"."<title id=".$time.">".$bing['title']."</title>n"."<titles id=".$time.">".$bing['titles']."</titles>n"."<more id=".$time.">".$bing['more']."</more>n";
fwrite($myfile, $all);
fclose($myfile);
Header("Location:$url");
}
}
?>
另外把修改前的代码放出来
<?php
if($_GET['idx']==null){
$_GET['idx']=0;
}
if($_GET['w']==null){
$_GET['w']='1366x768';
}
function bingImgFetch(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.bing.com/HPImageArchive.aspx?format=js&idx='.$_GET['idx'].'&n=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$re = curl_exec($ch);
curl_close($ch);
$re = json_decode($re,1);//电脑版返回内容
return array(
/* 更改图片尺寸,减小体积 */
'url' => str_replace('1920x1080',$_GET['w'],$re['images'][0]['url']),
);
}
$bingimg= bingImgFetch();
$imgurl='https://upyun-bing.woshiluo.dream.ren'.$bingimg['url'];
$url = $imgurl;
Header("Location:$url");
?>
完
这个部分愣是让我水了3周。各位大神轻喷,我只是个小白,若有不对请指出。 ]]>