(.+?)<\/fullstartdate>/is",$str,$cdata)){
}
$crdate = date('Y年m月d日 H:i', strtotime($cdata[1]));
$imgurl = 'http://cn.bing.com'.$matches[1];
echo "壁纸地址:" . $imgurl."
";
echo "发布时间:" . $crdate."
";
}
/**
* 将bing每日壁纸保存到 当前目录/background.jpg
*/
function GrabImage($imgurl, $dir, $filename='/background.jpg'){
if(empty($imgurl)){
return false;
}
$ext = strrchr($imgurl, '.');
if($ext == '.js' && $ext == ".html" && $ext == ".php"){
echo "Format not supported!";
return false;
}
$dir = realpath($dir);
$filename = $dir . $filename;
ob_start();
readfile($imgurl);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2 = fopen($filename , "w");
if(fwrite($fp2, $img)==true){
echo "壁纸大小:" . round($size / 1024) .'KB
';
echo "成功:当前壁纸已与Bing同步!
";
}
else{
echo "错误: 保存文件 ". $filename." 失败,请检查目录权限
";
}
fclose($fp2);
// echo "保存路径:" . $filename."
";
return $filename;
}
GrabImage($imgurl,dirname(__FILE__));
/**
* 返回bing每日壁纸
*/
// if($imgurl){
// header('Content-Type: image/JPEG');
// @ob_end_clean();
// @readfile($imgurl);
// @flush(); @ob_flush();
// exit();
// }else{
// exit('error');
// }
}
?>