File manager - Edit - /home/cipherteam/htdocs/cipherteam.in/API/Finance/TopLosersNSE.php
Back
<?php include_once("simple_html_dom.php"); include_once("ConnectToMarketData.php"); try { $html = file_get_html("https://money.rediff.com/losers/nse"); $tbody = $html->find('tbody',0); if(!$tbody) { throw new Exception('Exception message'); } $losers["LOSERS"] = 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 `nse_losers`"; $con->query($sql); $first = false; } $name = trim($tr->find('td', 0)->plaintext); $prePrice = trim($tr->find('td', 1)->plaintext); $prePrice = str_replace(",","",$prePrice); $price = trim($tr->find('td', 2)->plaintext); $price = str_replace(",","",$price); $changeper = $tr->find('td', 3)->plaintext; $change = ((float)$price-(float)$prePrice); $change = round($change, 2); $changeper = $changeper.'%'; $loser = array( 'NAME'=>$name, 'PRICE'=>$price, 'CHANGE'=>$change, 'CHANGEPER'=>$changeper ); $sql = "INSERT INTO `nse_losers` (`name`, `price`, `changeprice`, `changeper`) VALUES ('$name', '$price', '$change', '$changeper');"; $con->query($sql); array_push($losers["LOSERS"],$loser); } $losers["success"] = 1; echo json_encode($losers); } catch(Exception $e) { $sql = "SELECT `name` AS 'NAME',`price` AS 'PRICE',`changeprice` AS 'CHANGE',`changeper` AS 'CHANGEPER' FROM `nse_losers`"; $rows = $con->query($sql); $losers["LOSERS"] = array(); if($rows->num_rows > 0) { while($row = $rows->fetch_assoc()) { $div = array(); $div = $row; array_push($losers["LOSERS"],$div); } $losers["success"] = 1; echo json_encode($losers); } } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings