-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduo_json.php
More file actions
38 lines (35 loc) · 1.22 KB
/
duo_json.php
File metadata and controls
38 lines (35 loc) · 1.22 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
<?php
include('simple_html_dom.php');
$dom = new DomDocument;
$dom->loadHtmlFile('nbs.html');
$xpath = new DomXPath($dom);
// collect header names
$headerNames = array();
foreach ($xpath->query('//table[@id="index:spisakDeviza"]//th') as $node) {
$headerNames[] = $node->nodeValue;
}
// collect data
$data = array();
foreach ($xpath->query('//tbody[@id="index:spisakDeviz:tbody_element"]/tr') as $node) {
$rowData = array();
foreach ($xpath->query('td', $node) as $cell) {
$rowData[] = $cell->nodeValue;
}
$data[] = array_combine($headerNames, $rowData);
}
if (is_array($data) || is_object($data)) {
$result = array();
foreach($data as $row) {
$sell_rate = $row['PRODAJNI KURS'];
$buy_rate = $row['KUPOVNI KURS'];
if(isset($_GET['to_original'])) {
$sell_rate = 1/$row['PRODAJNI KURS'];
$buy_rate = 1/$row['KUPOVNI KURS'];
}
$arr = array("currency_code"=>$row['ŠIFRA VALUTE'], "country_name"=>$row['NAZIV ZEMLJE'], "currency_name"=>$row['OZNAKA VALUTE'], "sell_rate"=>$sell_rate, "buy_rate"=>$buy_rate);
array_push($result,$arr);
}
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}