File manager - Edit - /home/cipherteam/htdocs/cipherteam.in/API/Finance/world-indices.php
Back
<?php include_once("Market.php"); if(isMarketOpen()) { include_once("simple_html_dom.php"); include_once("ConnectToMarketData.php"); try { $html = file_get_html("https://money.rediff.com/indices/world"); $tbody = $html->find('tbody',1); if(!$tbody) { throw new Exception('Exception message'); } $indices["INDICES"] = array(); $first = true; $no = 1; foreach($tbody->find('tr') as $tr) { if($first) { $sql = "DELETE FROM `world_indices`"; $con->query($sql); $first = false; } $name = $tr->find('td', 1)->plaintext; $price = $tr->find('td', 2)->plaintext; $pricetmp = str_replace(' ','',$price); $pricetmp = str_replace(',','',$pricetmp); $chng = $tr->find('td', 3)->plaintext; $chngtmp = str_replace('+','',$chng); $chngtmp = str_replace('-','',$chngtmp); $changeper = ($chngtmp*100)/($pricetmp); if($changeper>0) $changeper = '+'.round($changeper, 2); else $changeper = round($changeper, 2); $changeper = $changeper.'%'; $indice = array( 'NAME'=>$name, 'PRICE'=>$price, 'CHANGE'=>$chng, 'CHANGEPER'=>$changeper ); array_push($indices["INDICES"],$indice); $sql = "INSERT INTO `world_indices` (`name`, `price`, `changeval`, `changeper`) VALUES ('$name','$price',$chng,'$changeper');"; $con->query($sql); if($no == 22) break; $no = $no + 1; } $indices["success"] = 1; echo json_encode($indices); } catch(Exception $e) { $sql = "SELECT `name` AS 'NAME',`price` AS 'PRICE',`changeval` AS 'CHANGE',`changeper` AS 'CHANGEPER' FROM `world_indices`;"; $rows = $con->query($sql); $indices["INDICES"] = array(); if($rows->num_rows > 0) { while($row = $rows->fetch_assoc()) { $div = array(); $div = $row; array_push($indices["INDICES"],$div); } $indices["success"] = 1; echo json_encode($indices); } } } else { include_once("ConnectToMarketData.php"); $sql = "SELECT `name` AS 'NAME',`price` AS 'PRICE',`changeval` AS 'CHANGE',`changeper` AS 'CHANGEPER' FROM `world_indices`;"; $rows = $con->query($sql); $indices["INDICES"] = array(); if($rows->num_rows > 0) { while($row = $rows->fetch_assoc()) { $div = array(); $div = $row; array_push($indices["INDICES"],$div); } $indices["success"] = 1; echo json_encode($indices); } } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.03 |
proxy
|
phpinfo
|
Settings