This repository was archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgdpy.php
More file actions
53 lines (51 loc) · 2.03 KB
/
gdpy.php
File metadata and controls
53 lines (51 loc) · 2.03 KB
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
43
44
45
46
47
48
49
50
51
52
53
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$year = $_GET['year'];
$txtyear = strval($year).".txt";
if(file_exists("cache/".$txtyear)){
$myfile = fopen("cache/".$txtyear,"r") or die("Unable to open file!");
echo fread($myfile,filesize("cache/".$txtyear));
fclose($myfile);
exit();
}
$yearlist = array();
$url = "https://www.myhora.com/%E0%B8%AB%E0%B8%A7%E0%B8%A2/%E0%B8%9B%E0%B8%B5-".strval($year).".aspx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$peryear = array();
$dom = new DOMDocument();
$dom->loadHTML($response);
$dom->preserveWhiteSpace = false;
$bigel = $dom->getElementsByTagName('font');
foreach($bigel as $val){
if(is_numeric(strpos($val ->nodeValue, 'ตรวจสลากกินแบ่งรัฐบาล'))){
$day = explode(" ", substr($val ->nodeValue, 74));
switch ($day[2]){
case 'มกราคม' : $monthnum="01"; break;
case 'กุมภาพันธ์' : $monthnum="02"; break;
case 'มีนาคม' : $monthnum="03"; break;
case 'เมษายน' : $monthnum="04"; break;
case 'พฤษภาคม' : $monthnum="05"; break;
case 'มิถุนายน' : $monthnum="06"; break;
case 'กรกฎาคม' : $monthnum="07"; break;
case 'สิงหาคม' : $monthnum="08"; break;
case 'กันยายน' : $monthnum="09"; break;
case 'ตุลาคม' : $monthnum="10"; break;
case 'พฤศจิกายน' : $monthnum="11"; break;
case 'ธันวาคม' : $monthnum="12"; break;
}
array_unshift($peryear,sprintf("%02d",$day[0]).$monthnum.$day[3]);
}
}
foreach($peryear as $val){
array_push($yearlist,$val);
}
$file = fopen("cache/".strval($year).".txt","w");
fwrite($file,json_encode($yearlist));
fclose($file);
echo json_encode($yearlist);
?>