Skip to content

Instantly share code, notes, and snippets.

@oriolrivera
Created July 4, 2014 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save oriolrivera/f7034dd1e9fc151278fb to your computer and use it in GitHub Desktop.
Save oriolrivera/f7034dd1e9fc151278fb to your computer and use it in GitHub Desktop.
Conversor de moneda usando la API de Google
<?php
/* conversor_divisas()
*
* Conversor de moneda usando la API de Google
*/
function currency($from, $to, $amount)
{
$content = file_get_contents('https://www.google.com/finance/converter?a='.$amount.'&from='.$from.'&to='.$to);
$doc = new DOMDocument;
@$doc->loadHTML($content);
$xpath = new DOMXpath($doc);
$result = $xpath->query('//*[@id="currency_converter_result"]/span')->item(0)->nodeValue;
return str_replace(' '.$to, '', $result);
}
echo currency('USD', 'DOP', 1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment