-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
42 lines (36 loc) · 1.26 KB
/
api.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
<?php
ob_start();
error_reporting(0);
header('Content-Type: application/json');
function currency()
{
$url = file_get_contents("https://www.tgju.org/currency");
preg_match_all('#<tr data-market-row="price_(.*?)" (.*?)[\r\n]<th><span class="(.*?)"></span>(.*?)</th>[\r\n]<td class="nf">(.*?)</td>[\r\n]<td class="nf"><span class="(.*?)">(.*?)</span></td>[\r\n]<td>(.*?)</td>[\r\n]<td>(.*?)</td>[\r\n]<td>(.*?)</td>#', $url, $result);
for ($i = 0; $i < count($result[6]) - 1; $i++) {
switch ($result[6][$i]) {
case "high":
$change = "high";
break;
case "low":
$change = "low";
break;
default:
$change = "none";
break;
}
$array = [
'name' => $result[4][$i],
'id' => $result[1][$i],
'price' => $result[5][$i],
'change' => $change,
'changeRate' => $result[7][$i],
'least' => $result[8][$i],
'highest' => $result[9][$i],
'time' => $result[10][$i],
];
$results[] = $array;
}
return $results;
}
$res = ['creator' => 'Mahdyar Entezami', 'currency' => currency()];
echo json_encode($res, 128 | 256);