コード例 #1
0
ファイル: currency.php プロジェクト: killsaw/f3-plugins
 /**
 		Retrieve currency conversion from Google Finance.
 			@return bool|float
 			@param $amount float
 			@param $from string Currency to convert from. e.g. USD
 			@param $to string Currency to convert to. e.g. EUR
 			@public
 	**/
 public static function convertAmount($amount, $from, $to, $quiet = false)
 {
     $from = strtoupper($from);
     $to = strtoupper($to);
     if (!is_numeric($amount)) {
         trigger_error(self::TEXT_AmountNotNumber);
         return false;
     }
     // Workaround for empty ENV. Causes an issue in f3::http()
     if (!isset($_ENV['OS'])) {
         $_ENV['OS'] = 'Windows';
     }
     $data = f3::http("GET http://www.google.com/finance/converter", http_build_query(array('a' => $amount, 'from' => $from, 'to' => $to)));
     if (preg_match('/<span class=bld>(.+) (.+)<\\/span>/', $data, $match)) {
         if ($match[2] == $to) {
             return (double) $match[1];
         }
     }
     if (!$quiet) {
         trigger_error(self::TEXT_NoConversion);
     }
     return false;
 }