Guest User

Untitled

a guest
Aug 6th, 2012
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function getCurrencyConversion($currency = 'USD'){
  2.  
  3.         $content = file_get_contents("http://br.financas.yahoo.com/q?s={$currency}BRL=X");
  4.         preg_match('/<span id=\"yfs_p20_'. strtolower($currency) .'brl=x\">(.*)<\/span>/', $content, $matches, PREG_OFFSET_CAPTURE);
  5.         preg_match('/<span id=\"yfs_b00_'. strtolower($currency) .'brl=x\">(.*)<\/span>/', $content, $matches2, PREG_OFFSET_CAPTURE);
  6.         preg_match('/<span id=\"yfs_a00_'. strtolower($currency) .'brl=x\">(.*)<\/span>/', $content, $matches3, PREG_OFFSET_CAPTURE);
  7.         $variation = substr($matches[0][0], 29, 29);
  8.         $buyPrice = substr($matches2[0][0], 28, 9);
  9.         $sellPrice = substr($matches3[0][0], 28, 9);
  10.         $currencyVariation = preg_replace('/\)/', '', $variation);
  11.  
  12.  
  13.         echo <<<CURRENCY
  14.  
  15.         <td><strong>{$currency}</strong></td>
  16.         <td>$buyPrice</td>
  17.         <td>$sellPrice</td>
  18.         <td class="green"><strong>$currencyVariation</strong></td>
  19. CURRENCY;
  20.        
  21.  
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment