Skip to content

Commit

Permalink
10022015 - se agregan archivos a repo
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciojofre committed Feb 10, 2015
0 parents commit cfff6b4
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
65 changes: 65 additions & 0 deletions obtener_uf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
error_reporting(0);

function nombreMes($numero_mes){

$mesArray = array(
1 => "Enero",
2 => "Febrero",
3 => "Marzo",
4 => "Abril",
5 => "Mayo",
6 => "Junio",
7 => "Julio",
8 => "Agosto",
9 => "Septiembre",
10 => "Octubre",
11 => "Noviembre",
12 => "Diciembre",
13 => "Todos"
);

return $mesArray[$numero_mes];
}

function imprimirUF($mes_usr,$anio){

$contenido = file_get_contents("http://www.sii.cl/pagina/valores/uf/uf".$anio.".htm");

$dom = new DOMDocument;
$dom->loadHTML($contenido);

foreach($dom->getElementsByTagName('tr') as $meses => $tr){

foreach($tr->getElementsByTagName('td') as $dias => $td){
$valores_por_mes[$dias][$meses] = $td->nodeValue;
}
}

$array_uf = array();
foreach($valores_por_mes as $meses => $arreglo_dias){

$mes = intval($meses+1);
if(strlen($mes)==1){
$mes = "0".$mes;
}else{
$mes;
}

foreach($arreglo_dias as $dias => $valor){
if($mes == $mes_usr || $mes_usr == 13){
if (strpos($valor,'.') !== false) {
if(strlen($dias)==1){ $dias = "0".$dias; }else{ $dias; }
$fecha = $dias."-".$mes."-".$anio;
$array_uf[$fecha] = $valor;
}
}
}
}

echo '<pre>';
echo '<p> ' . nombreMes($mes_usr) . '</p>';
echo json_encode($array_uf);
echo '</pre>';
}
?>
26 changes: 26 additions & 0 deletions vista_uf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p>Seleccione mes</p>
<form method="POST" action="<?php $_SERVER["PHP_SELF"] ?>">
<select name="mes" onchange="">
<option value="13">Todos</option>
<option value="01">Enero</option>
<option value="02">Febrero</option>
<option value="03">Marzo</option>
<option value="04">Abril</option>
<option value="05">Mayo</option>
<option value="06">Junio</option>
<option value="07">Julio</option>
<option value="08">Agosto</option>
<option value="09">Septiembre</option>
<option value="10">Octubre</option>
<option value="11">Noviembre</option>
<option value="12">Diciembre</option>
</select>
<input type="submit" value="enviar">
</form>

<?php
if($_POST["mes"]){
require 'obtener_uf.php';
return imprimirUF($_POST["mes"],date("Y"));
}
?>

0 comments on commit cfff6b4

Please sign in to comment.