File manager - Edit - /home/cipherteam/htdocs/cipherteam.in/API/Finance/TopGainersBSE.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/gainers/bse"); $tbody = $html->find('tbody',0); if(!$tbody) { throw new Exception('Exception message'); } $gainers["GAINERS"] = array(); $tmp = $tbody->find('tr',0); if(!$tmp) { throw new Exception('Exception message'); } $first = true; foreach($tbody->find('tr') as $tr) { if($first) { $sql = "DELETE FROM `bse_gainers`"; $con->query($sql); $first = false; } $name = trim($tr->find('td', 0)->plaintext); $prePrice = trim($tr->find('td', 2)->plaintext); $prePrice = str_replace(",","",$prePrice); $price = trim($tr->find('td', 3)->plaintext); $price = str_replace(",","",$price); $changeper = $tr->find('td', 4)->plaintext; $change = ((float)$price-(float)$prePrice); $change = round($change, 2); $change = $change.''; $gainer = array( 'NAME'=>$name, 'PRICE'=>$price, 'CHANGE'=>$change, 'CHANGEPER'=>$changeper.'%' ); $sql = "INSERT INTO `bse_gainers` (`name`, `price`, `changeprice`, `changeper`) VALUES ('$name', '$price', '$change', '$changeper');"; $con->query($sql); array_push($gainers["GAINERS"],$gainer); } $gainers["success"] = 1; echo json_encode($gainers); } catch(Exception $e) { $sql = "SELECT `name` AS 'NAME',`price` AS 'PRICE',`changeprice` AS 'CHANGE',`changeper` AS 'CHANGEPER' FROM `bse_gainers`"; $rows = $con->query($sql); $gainers["GAINERS"] = array(); if($rows->num_rows > 0) { while($row = $rows->fetch_assoc()) { $div = array(); $div = $row; array_push($gainers["GAINERS"],$div); } $gainers["success"] = 1; echo json_encode($gainers); } } } else { include_once("ConnectToMarketData.php"); $sql = "SELECT `name` AS 'NAME',`price` AS 'PRICE',`changeprice` AS 'CHANGE',`changeper` AS 'CHANGEPER' FROM `bse_gainers`"; $rows = $con->query($sql); $gainers["GAINERS"] = array(); if($rows->num_rows > 0) { while($row = $rows->fetch_assoc()) { $div = array(); $div = $row; array_push($gainers["GAINERS"],$div); } $gainers["success"] = 1; echo json_encode($gainers); } } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.13 |
proxy
|
phpinfo
|
Settings