Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/08/2013, 09:38
thesyd
 
Fecha de Ingreso: abril-2013
Mensajes: 2
Antigüedad: 11 años
Puntos: 0
Pregunta Listado con PHP desde archivo TXT

Hola.. El asunto es el siguiente.. quiero leer un archivo de texto (TXT) desde mi archivo PHP. y que lea linea a linea y a partir de cada una de ellas obtenga una serie de datos de ancho prefijado. Estos datos tienen que utilizarse luego para ser mostrados o no segun los siguientes parametros:
Linea del TXT:
4 caracteres para codigo, 100 para detalle, 10 pre, 10 desde, 10 hasta, 4 imagen,200 por si acaso.

Comparativas:
Si desde y Hasta son iguales emito un mensaje distinto que si no.
Si Hasta es menor que Ahora (fecha) no se emite contenido
Del renglon del TXT se sacan todos esos contenidos y se dibuja con codigo HTML en tablas.

Este es el codigo que genere al respecto.

<?php
$file = fopen("1.txt", "r") or exit("Unable to open file!");
while(!feof($file))
{$fila=str(fgets($file)); echo $fila;
$fecahora=new DateTime("now");
$fecahora2=(substr($fecahora,0,4)).(substr($fecaho ra,5,2)).(substr($fecahora,8,2));
$cod=(substr($fila,0,4);
$det=(substr($fila,4,100);
$pre=(substr($fila,104,10);
$img=(substr($fila,0,4).".jpg";
$fecini=new DateTime('(substr($fila,114,10)');
$fecfin2=(substr($fecfin,0,4)).(substr($fecfin,5,2 )).(substr($fecfin,8,2));
$fecfin=new DateTime('(substr($fila,124,10)');
if ($fecini == $fecfin) {$fec="el dia: ".(substr($fecini,4,2).(substr($fecini,7,2));}else {$fec="desde: ".(substr($fecini,4,2).(substr($fecini,7,2))." hasta: ".(substr($fecfin,4,2).(substr($fecfin,7,2));}
if ($fecfin2 < $fecahora2)
{echo '
<table width="500" border="1" cellspacing="1" cellpadding="1">
<tr>
<td><table width="500" border="1" cellspacing="1" cellpadding="1">
<tr>
<td height="200" width="200"><img src="img/'.$img.'"></td>
<td><table width="300" border="1" cellspacing="1" cellpadding="1">
<tr>
<td>
<table width="300" border="1" cellspacing="1" cellpadding="1">
<tr>
<td height="130" align="center"><font size="+3">'.$det.'</font></td>
</tr>
<tr>
<td height="20">Oferta valida '.$fec.'</td>
</tr>
</table></td>
</tr>
<tr>
<td height="50"><table width="300" border="1" cellspacing="1" cellpadding="1">
<tr>
<td width="20"><font size="+1" align="center">codart '.$cod.'</font></td>
<td align="center"><font size="+5">'.$pre.'</font></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
';}
}
fclose($file);
?>

Al probarlo en un server de testeos en internet me arrojo error en linea 8