-
-
Save macknilan/878ae367d3066ee5090cda8351a13f22 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