$limit = 5; //不需要的公告,請自行註解掉(在最左邊加上//) $url_arr['一般公告'] = 'https://www.doe.gov.taipei/OpenData.aspx?SN=A53E0BA10DD4457E'; $url_arr['幼兒園'] = 'https://www.doe.gov.taipei/OpenData.aspx?SN=D5AD2C5A7A85502C'; $url_arr['國小'] = 'https://www.doe.gov.taipei/OpenData.aspx?SN=A06275FDC88942AB'; $url_arr['國中'] = 'https://www.doe.gov.taipei/OpenData.aspx?SN=2376933CA35541CB'; $url_arr['高中職'] = 'https://www.doe.gov.taipei/OpenData.aspx?SN=8FDEB38F0F17B561'; $url_arr['終身教育'] = 'https://www.doe.gov.taipei/OpenData.aspx?SN=711FA93AC6D09A71'; if (function_exists('curl_init')) { if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/easy_responsive_tabs.php")) { redirect_header("index.php", 3, '需要最新版TadTools'); } include_once XOOPS_ROOT_PATH . "/modules/tadtools/easy_responsive_tabs.php"; $responsive_tabs = new easy_responsive_tabs('#tpNewsTab'); $responsive_code = $responsive_tabs->rander(); $tabs = $tab_content = ''; foreach ($url_arr as $tab_title => $url) { $data = ''; $ch = curl_init(); $timeout = 2; curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); $tabs .= "
  • $tab_title
  • "; // echo $data; if ($data) { if (substr($data, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { $data = substr($data, 3); } $news_arr = json_decode($data, true); // echo json_last_error() . "\n"; // 4 // echo json_last_error_msg() . "\n"; // Syntax error, malformed JSON $all_news = array(); $i = 0; if ($news_arr) { foreach ($news_arr as $news) { if (isset($news['發布日期']) and isset($news['Source']) and isset($news['title']) and isset($news['發布單位'])) { $date = $news['發布日期']; $all_news[$date]['link'] = $news['Source']; $all_news[$date]['title'] = $news['title']; $all_news[$date]['unit'] = $news['發布單位']; } $i++; } krsort($all_news); $i = 0; $tab_content .= "
    "; foreach ($all_news as $date => $news) { $date = substr($date, 0, 10); $tab_content .= " "; $i++; if ($i >= $limit) { break; } } $tab_content .= "
    標題 發布日期 發布機關
    {$date} {$news['title']} {$news['unit']}
    "; } else { var_export($news_arr); echo "無法解析資料"; } } else { echo "抓不到 {$url} 的資料"; } } echo $responsive_code . '
    ' . $tab_content . '
    '; } else { echo "請安裝 CURL"; }