百度历史上的今天api
作者:
秒速五厘米

php封装的api直接保存就可以输出json格式了
public function lishihingtian()
{
$riqi = Cache::get('riqi');
if (!$riqi) {
// 获取日期
$month = date('m', time());
$day = date('d', time());
// 获取百度接口原始数据
$url = "https://baike.baidu.com/cms/home/eventsOnHistory/" . $month . '.json';
$data = file_get_contents($url);
$json_baidu = json_decode($data, true);
// 简单封装处理
$array_tmp = array();
$i = 0;
foreach ($json_baidu[$month][$month . $day] as $tmp) {
// echo $tmp['year'].'年:';
// echo strip_tags($tmp['title']).'';
$array_tmp[$i] = [
'year' => $tmp['year'],
'title' => strip_tags($tmp['title'])
];
$i++;
}
$json_output = [
$month . $day => $array_tmp
];
//输出
header('Content-type:text/json');
$riqi = current($json_output);
Cache::set('riqi', $riqi, 3600);
}
return $riqi;
}