Eric_W

Exchange data

May 19th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. function getExchangeData()
  2. {
  3.     $doc = new DomDocument;
  4.     $doc->validateOnParse = true;
  5.     @$doc->loadHTMLFile('http://www.roblox.com/marketplace/tradecurrency.aspx');
  6.  
  7.     $xpath = new DOMXpath($doc);
  8.     $statWrappers = $xpath->query("*//div[@id='CurrencyQuotePane']//div[@class='TableRow']");
  9.  
  10.     $stats = array();
  11.  
  12.     if (!is_null($statWrappers))
  13.     {
  14.         foreach ($statWrappers as $statWrapper)
  15.         {
  16.             $pair    = $xpath->query("div[@class='Pair']/text()", $statWrapper)->item(0)->textContent;
  17.             $rate    = $xpath->query("div[@class='Rate']/text()", $statWrapper)->item(0)->textContent;
  18.             $highLow = $xpath->query("div[@class='HighLow']/text()", $statWrapper)->item(0)->textContent;
  19.             $spread  = $xpath->query("div[@class='Spread']/text()", $statWrapper)->item(0)->textContent;
  20.            
  21.             $rate = preg_split('/\//',$rate);
  22.             $rate[0] = floatval($rate[0]);
  23.             $rate[1] = floatval($rate[1]);
  24.            
  25.             $highLow = preg_split('/\//',$highLow);
  26.             $high = floatval($highLow[0]);
  27.             $low = floatval($highLow[1]);
  28.            
  29.             $stats[$pair] = array(
  30.                 'rate' => $rate,
  31.                 'high' => $high,
  32.                 'low' => $low,
  33.                 'spread' => floatval($spread)
  34.             );
  35.         }
  36.         return $stats;
  37.     }
  38.     return false;  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment