Hi
These days I have trouble displaying RSS tabular information on a php page. The problem is I can't seem to sort out this RSS information. Moreover, I need to get Total for 'bestBuy'. I'm out of my field with php, can anybody give me a hand, or a program for processing/converting RSS into php? My aim is to display public information about rates.
<?php
$list_code = array();
function round2d($valor) {
$float_redondeado=round($valor * 100) / 100;
return $float_redondeado;
}
function read_code() {
$content = file_get_contents("http://www.bse-sofia.bg/shared/real/security.php");
$x = new SimpleXmlElement($content);
global $list_code;
foreach($x->item as $entry) {
$list_code[strval($entry->isin)] = strval($entry->code);
}
}
function search_code($isin){
global $list_code;
return $list_code[$isin];
}
function read_values($nombre_archivo){
$archiv_XML = file_get_contents ($nombre_archivo);
if (empty($archiv_XML))
die("The xml file can not be found");
preg_match_all("|<item>(.*)</item>|sU", $archiv_XML, $items);
$list_node = array();
foreach ($items[1] as $key => $item)
{
preg_match("|<bse:isin>(.*)</bse:isin>|s", $item, $isin);
preg_match("|<bse:lastPrice>(.*)</bse:lastPrice>|s", $item, $lastPrice);
preg_match("|<bse:chgPrice>(.*)</bse:chgPrice>|s", $item, $chgPrice);
preg_match("|<bse:bay>(.*)</bse:bay>|s", $item, $bestBuy);
preg_match("|<bse:sell>(.*)</bse:sell>|s", $item, $bestSell);
preg_match("|<bse:numShares>(.*)</bse:numShares>|s", $item, $numShares);
preg_match("|<bse:avgPrice>(.*)</bse:avgPrice>|s", $item, $avgPrice);
$list_node[$key]['isin'] = $isin[1];
$list_node[$key]['lastPrice'] = $lastPrice[1];
$list_node[$key]['chgPrice'] = $chgPrice[1];
$list_node[$key]['bestBuy'] = $bestBuy[1];
$list_node[$key]['bestSell'] = $bestSell[1];
$list_node[$key]['numShares'] = $numShares[1];
$list_node[$key]['avgPrice'] = $avgPrice[1];
}
read_code();
echo '<table>';
echo '<tbody>';
$result = count($list_node);
for ($i = 0; $i < $result; $i++)
{
$isin = $list_node[$i]['isin'];
echo '<tr><td><b>' . search_code($isin) . '</b></td>';
echo '<td align="right">' . round2d($list_node[$i]['lastPrice']) . '</td>';
if (round2d($list_node[$i]['chgPrice'])<0) {
echo '<td align="right"><font color="#e10000">' . round2d($list_node[$i]['chgPrice']) . '</font></td>';
}else{
echo '<td align="right"><font color="#507517">' . round2d($list_node[$i]['chgPrice']) . '</font></td>';
}
echo '<td align="right">' . round2d($list_node[$i]['numShares']) . '</td>';
echo '<td align="right">' .$a= round(($list_node[$i]['avgPrice'])*($list_node[$i]['numShares']) ) . '</td>';
echo '<td align="right">' . round2d($list_node[$i]['bestBuy']) . '</td>';
echo '<td align="right">' . round2d($list_node[$i]['bestSell']) . '</td>';
echo '<tr><td colspan="7"><div style="border-bottom: 1px dashed rgb(197, 197, 197); padding: 1px; font-size: 1px;"> </div></td></tr>';
}
echo '</tbody> </table>';
$archiv_XML = "http://rss.bse-sofia.bg/?page=ShortBulletin";
}
read_values("http://rss.bse-sofia.bg/?page=ShortBulletin");
?>