Created
March 27, 2019 04:03
-
-
Save istiyakamin/90c8ff0e004540ed344fa834bc56abd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: application/json'); | |
$method = $_SERVER['REQUEST_METHOD']; | |
//GET Request | |
switch ($method) { | |
case 'GET': // read data | |
getOperation(); | |
break; | |
} | |
//GET Function | |
function getOperation(){ | |
error_reporting(E_ALL ^ E_WARNING); | |
$sUrl = 'https://www.cse.com.bd/market/current_price'; | |
$html = file_get_contents($sUrl); | |
$dom = new DOMDocument(); | |
@$dom->loadHTML($html); | |
$xpath = new DomXPath($dom); | |
$a = []; | |
$elements = $xpath->query('//*[@id="dataTable"]/tbody'); | |
foreach($elements as $e){ | |
$len = $e->childNodes->length; | |
for($n=0;$n<=$len;$n++){ | |
$scrip = $xpath->query('tr', $e)[$n]->childNodes[2]->nodeValue; | |
$ltp = $xpath->query('tr', $e)[$n]->childNodes[4]->nodeValue; | |
$open = $xpath->query('tr', $e)[$n]->childNodes[6]->nodeValue; | |
$high = $xpath->query('tr', $e)[$n]->childNodes[8]->nodeValue; | |
$low = $xpath->query('tr', $e)[$n]->childNodes[10]->nodeValue; | |
$ycp = $xpath->query('tr', $e)[$n]->childNodes[12]->nodeValue; | |
//$trade = $xpath->query('tr', $e)[$n]->childNodes[14]->nodeValue; | |
//$value = $xpath->query('tr', $e)[$n]->childNodes[16]->nodeValue; | |
$volume = $xpath->query('tr', $e)[$n]->childNodes[18]->nodeValue; | |
if($ycp>0){ | |
$percentage=(($ltp-$ycp)/$ycp); | |
} else { | |
$percentage = 0; | |
} | |
$a[] = [ | |
'scrip_id'=>$scrip, | |
'exchange'=>'CSE', | |
'category_id'=>'X', | |
'buy_quantity'=>'0', | |
'buy_price'=>'0', | |
'sale_quantity'=>'0', | |
'sale_price'=>'0', | |
'ltp'=>$ltp, | |
'change'=>$ltp-$ycp, | |
'imgs'=>'0', | |
'percentage'=>$percentage, | |
'volume'=>$volume, | |
'time'=>'0', | |
'high_price'=>$high, | |
'low_price'=>$low, | |
'market_pe'=>'0', | |
'ycp'=>$ycp, | |
'open_price'=>$open, | |
'close_price'=>'0' | |
]; | |
} | |
$data = json_encode($a); | |
echo json_encode($data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment