I get data for prices from an outside provider. I have a php file I call getter.php. This file pulls back the data I need based on the arrays set. Once I get the arrays set. I can use the prices I am getting from my outside provider here is an example out of the code.
if ($strName == "Gold") {
$GoldAsk = $strAsk;
$GoldAsk = number_format ($GoldAsk, 2);
Once I have $GoldAsk set from my array I am able to use this getter file and use <?php print "$GoldAsk"; ?> to get my number but I am would like to do some calculations with this number. So I create a second php file call calculate. Here is what I have in that file.
<?php // ROUTINE include ('getter.php'); $Kit1 = 1.8442 * $GoldAsk; ?>When I try to display this out in my html file <?php print "$Kit1"; ?> I get some odd number it is not calculating correctly. I can not figure out if I can get <?php print "$GoldAsk"; ?> to display why my basic formula does not work? I am posting the original getter.php file that I use to get the raw data from my provider below.
<?php require_once('class/IsterXmlSimpleXMLImpl.php'); function getQuoteList($arrSymbols = array("XAUUSDOZ","XAGUSDOZ","XPTUSDOZ","XPDUSDOZ")) { $provider = "*******"; $username = "******"; $password = "*******"; $dateTimeFormat = "HH:mm:ss"; //The format for returned timestamps $timezone = "America/New_York"; //The timezone to which timestamps should be converted //Returns a full text-representation of the XML document //with the given URL. // function getXMLSource($url) // { // $str = file_get_contents($url); // return $str; // } //Create a string representation of the symbols, seperated by "|" $strSymbols = ""; $start = 0; foreach($arrSymbols as $symbol) { $strSymbols = $strSymbols.$symbol."|"; } //Load XML data source $impl = new IsterXmlSimpleXMLImpl; $objXMLDom = $impl->load_file("http://balancer.netdania.com/StreamingServer/StreamingServer?xml=price&group=".$username."&pass=".$password."&source=".$provider."&symbols=".$strSymbols."&fields=10|11|14|15|25|2|3&time=".$dateTimeFormat."&tzone=".$timezone); //echo "
"; //print_r($objXMLDom); //echo ""; //echo "http://******.com/StreamingServer/StreamingServer?xml=price&group=".$username."&pass=".$password."&source=".$provider."&symbols=".$strSymbols."&fields=10|11|14|15|25|2|3&time=".$dateTimeFormat."&tzone=".$timezone; return $objXMLDom; } $objXMLDom = getQuoteList(); $i = 0; $arrNames = array("Gold","Silver"); //Loop through and display data for each instrument foreach ($objXMLDom->datafeed->children() as $quote) { $quoteinfo = $quote->attributes(); /*echo "
";
print_r($quoteinfo);
echo ""; */
$strName = $arrNames[$i];
$i++;
$strBid = $quoteinfo["f10"];
$strAsk = $quoteinfo["f11"];
$strChange = $quoteinfo["f14"];
$strPercChange = $quoteinfo["f15"];
$strHigh = $quoteinfo["f2"];
$strLow = $quoteinfo["f3"];
$strDateTime = $quote->CDATA();
if ($strName == "Gold") {
$GoldAsk = $strAsk;
$GoldAsk = number_format ($GoldAsk, 2);
}
if ($strName == "Silver") {
$SilverAsk = $strAsk;
$SilverAsk = number_format ($SilverAsk, 2);
}
}
$xml = null;
/*
print("The spot price of gold is currently -- $GoldAsk");
print(""); print("
"); print("The spot price of silver is currently -- $SilverAsk"); print("
"); print("
"); print date ('g:i a D. F j, Y'); */