Created
September 18, 2017 05:29
-
-
Save carloslopez1990/59f86445122618469beb1be311fffaee to your computer and use it in GitHub Desktop.
bcn.php
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 | |
define('BCN_URL', 'http://www.bcn.gob.ni/estadisticas/mercados_cambiarios/tipo_cambio/cordoba_dolar/mes.php'); | |
function getCambioMes( $mes, $anio ) { | |
if( strlen((int)$mes) == 1 ) | |
$mes = '0'.$mes; | |
preg_match_all('|<td><div align="center">(.*?)\-(.*?)</div></td>\s*<td><div align="center">(.*?)</div></td>|is', | |
file_get_contents(BCN_URL.'?mes='.$mes.'&anio='.$anio), $matches); | |
$ret = array(); | |
for ($i=0; $i < count( $matches[1] ); $i++) | |
$ret[$anio.'-'.$mes.'-'.$matches[1][$i]] = trim($matches[3][$i]); | |
return json_encode($ret); | |
} | |
function getCambioFecha( $fecha ) { | |
preg_match_all('|\d+\.\d+|', file_get_contents(BCN_URL.'?Fecha_inicial='.$fecha.'&Fecha_final='.$fecha), $matches); | |
return json_encode(array($fecha => $matches[0][0])); | |
} | |
print_r( getCambioMes( 9, 2017 ) ); | |
// print getCambioFecha( date('Y-m-d') ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment