Created
July 4, 2014 15:17
-
-
Save oriolrivera/f7034dd1e9fc151278fb to your computer and use it in GitHub Desktop.
Conversor de moneda usando la API de Google
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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