-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.php
42 lines (27 loc) · 1.2 KB
/
load.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//JSON 방식
<?php
require("Snoopy.class.php");
$URL = "https://open.neis.go.kr/hub/mealServiceDietInfo?KEY=c2a4b8fcdab24f92aaea45e7a1fa4512&Type=json&ATPT_OFCDC_SC_CODE=$ScCode&SD_SCHUL_CODE=$SdCode&MLSV_YMD=$date";
$snoopy = new Snoopy; // snoopy 생성
$snoopy->fetch($URL);
$return = json_decode($snoopy->results);
$meal = explode("<br />", $return->mealServiceDietInfo[1]->row[0]->DDISH_NM);
?>
<?php for($i=0; $i<sizeof($meal); $i++){ echo '<h2>'.preg_replace("/[0-9,.,()]/", "", $meal[$i]).'</h2><br/>'; } ?>
//XML 방식
<?php
$date = date("Ymd");
$xmlfile = 'https://open.neis.go.kr/hub/mealServiceDietInfo?ATPT_OFCDC_SC_CODE=K10&SD_SCHUL_CODE='.$sch_code.'&MLSV_YMD=202309&KEY=c2a4b8fcdab24f92aaea45e7a1fa4512';
$food_api = simplexml_load_file($xmlfile) or die("급식 정보를 불러오지 못했습니다!");
$serial = 1;
foreach ($food_api as $food):
$date_api = $food->MLSV_YMD;
$menu = $food->DDISH_NM;
$cal = $food->CAL_INFO;
if($date == $date_api) {
echo $menu;
echo '<br><span style="font-size:12px;color:gray;">'.$cal.'</span>';
}
$serial++;
endforeach;
?>