query("SET NAMES 'utf8' "); require_once('./conf/class.common.php'); $page = isset($_REQUEST['page']) ? trim($_REQUEST['page']) : '1'; if($page=="") $page=1; $get_page = ceil($page/2);// 一頁分2頁 /* 22:32 珮綺 參賽食譜api * JSON API: https://icook.tw/users/weiweinoodle/lists/1688172.json * User-Agent: 非空白即可 * 翻頁方式: ?page=1 */ /* 六篇示範食譜api https://icook.tw/users/weiweinoodle/lists/1688173.json 參賽食譜api https://icook.tw/users/weiweinoodle/lists/1688172.json */ //https://icook.tw/users/laurel/lists/1526427.json?page=1 $Agent="User-Agent: Mozilla/5.0\n"; $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" ) ); //範例食譜 $title_array = array('味味麵精燉肉燥湯麵','味味麵紅燒牛肉湯麵','味味麵海鮮湯麵','味味麵精燉肉燥湯麵','味味麵紅燒牛肉湯麵','味味麵海鮮湯麵'); $id_array = array(147024,147191,147203,147237,147241,147246); $file_url = "https://icook.tw/users/weiweinoodle/lists/1688173.json"; $context = stream_context_create($opts); $contents = file_get_contents($file_url,false,$context); $rtndata=json_decode($contents,true); if(count($rtndata)>0) { foreach($rtndata['recipes'] as $k => $v) { for($i=0; $i<6 ; $i++) { if($v['id']==$id_array[$i]) { $sampledata[$i] = $v; } } } } sort($sampledata); //echo json_encode($sampledata);exit; $tmp = array(); foreach($sampledata as $k => $v) { $v['title'] = $title_array[$k]; $tmp[] = $v; } $sampledata = $tmp; unset($tmp); //$sampledata = $rtndata['recipes']; //參賽 //$file_url = "https://icook.tw/users/laurel/lists/1526427.json?page=".$get_page; $file_url = "https://icook.tw/campaigns/weiweinoodle/entries.json?page=".$get_page; $context = stream_context_create($opts); $contents = file_get_contents($file_url,false,$context); $rtndata=json_decode($contents,true); //資料數量與分頁資訊 $metadata = $rtndata['meta']; //共多少頁 $pageSum = ceil($metadata['total']/6); $joindata = array(); //參賽資料 //json一次回傳12筆 //一頁只顯示六筆 if(count($rtndata)>0) { $start = ($page%2==1) ? 0 : 6; $end = $start+6; for($i = $start ; $i<$end ; $i++) { if(isset($rtndata['recipes'][$i]['id']) ) { $joindata[] = $rtndata['recipes'][$i]; } } } ?> 記憶中的味道 味味古早麵募集你記憶中的好味道
page:/