Php mettre un fichier texte en tableau
xunil2003
Messages postés
830
Statut
Membre
-
xunil2003 Messages postés 830 Statut Membre -
xunil2003 Messages postés 830 Statut Membre -
Bonjour,
Tout est dans le titre.
J'ai un fichier texte avec ceci dedans :
mais impossible d'afficher le résultat dans le navigateur, j'ai essayé plein de truc , rien a faire ?
La page du navigateur reste blanche, php ne signal aucune erreur ???
Merci
Tout est dans le titre.
J'ai un fichier texte avec ceci dedans :
30-06-2012 - 19:06:25 - serveur - cm15 E1 bri 15 - e1-15% - Crontab 30-06-2012 - 19:08:12 - serveur - cm15 E1 off - e1-off - Script bash 30-06-2012 - 22:38:17 - serveur - cm15 D8 off - Macro e5-off vers d8-off - Script bash
mais impossible d'afficher le résultat dans le navigateur, j'ai essayé plein de truc , rien a faire ?
La page du navigateur reste blanche, php ne signal aucune erreur ???
<?php
*
$tableau = array();
$handle = @fopen("/home/serveur/Domotique/rapports/ordres/2012-07-rapport-ordres.log", "r" );
if ($handle)
{
while (!feof($handle))
{
$buffer = fgets($handle, 4096);
$tableau[] = $buffer;
}
fclose($handle);
}
if ($tableau)
{
print_r($tableau);
}
else
{
echo "Le remplissage du tableau a échoué";
}
?>
Merci
A voir également:
- Php mettre un fichier texte en tableau
- Fichier bin - Guide
- Tableau word - Guide
- Comment réduire la taille d'un fichier - Guide
- Fichier epub - Guide
- Fichier rar - Guide
2 réponses
bonjour,
Finalement j'ai fait comme ci-dessous mais dans le tableau l'affichage n'est pas ligne par ligne dans les colonnes "Ordre X10" "Macro" "Executé par". Le code ne comprend pas quand il y a un espace et passe directement a la ligne ci-dessous .
le fichier texte est comme ceci
Merci.
Finalement j'ai fait comme ci-dessous mais dans le tableau l'affichage n'est pas ligne par ligne dans les colonnes "Ordre X10" "Macro" "Executé par". Le code ne comprend pas quand il y a un espace et passe directement a la ligne ci-dessous .
le fichier texte est comme ceci
30/06/2012 - 19:06:25 - serveur - cm15 E1 bri 15 - e1-15% - Crontab 30/06/2012 - 19:08:12 - serveur - cm15 E1 off - aucun - Script bash 30/06/2012 - 22:38:17 - serveur - cm15 D8 off - Macro e5-off vers d8-off - Script bash 22/07/2012 - 21:17:12 - root - cm15 F2 on - f2-on - Aucun - Asterisk 22/07/2012 - 21:17:24 - root - cm15 F2 off - f2-off - Aucun - Asterisk 22/07/2012 - 21:17:12 - root - cm15 E1 on - e1-on - Aucun - Script bash 22/07/2012 - 21:17:24 - root - cm15 E1 off - e1-off - Aucun - Script bash
<?php
// le fichier
$fichier1 = '/home/serveur/Domotique/rapports/ordres/2012-07-rapport-ordres.log';
// declaration variable $villes
//$villes='colone1';
// ouverture du fichier
$fp=fopen($fichier1,'r');
while (!feof($fp)) {
// lecture et decoupage des lignes à chaque ;
$position=explode("- ",fgets($fp,255));
// $position dans la ligne commence à zero
$date2.=$position[0];
$heure.=$position[1];
$user.=$position[2];
$ordre_x10.=$position[3];
$fichier2.=$position[4];
$macro.=$position[5];
$execute_par.=$position[6];
}
// fermeture du fichier
fclose($fp);
?>
<table style="text-align: left; width: auto;" border="1"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; width: 19px;">Date<br>
</td>
<td style="vertical-align: top; width: 19px;">Heure<br>
</td>
<td style="vertical-align: top; width: 19px;">User<br>
</td>
<td style="vertical-align: top; width: 50px;">Ordre x10<br>
</td>
<td style="vertical-align: top; width: 19px;">Fichier<br>
</td>
<td style="vertical-align: top; width: 19px;">Macro<br>
</td>
<td style="vertical-align: top; width: 19px;">Executé par<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;width: 19px;"><br>
</td>
<td style="vertical-align: top;width: 19px;"><br>
</td>
<td style="vertical-align: top;width: 19px;"><br>
</td>
<td style="vertical-align: top;width: 50px;"><br>
</td>
<td style="vertical-align: top;width: 19px;"><br>
</td>
<td style="vertical-align: top;width: 19px;"><br>
</td>
<td style="vertical-align: top;width: 19px;"><br>
</td>
</tr>
<tr>
<td style="vertical-align: top;width: 19px;"><?php echo $date2; ?><br>
</td>
<td style="vertical-align: top;width: 19px;"><?php echo $heure; ?><br>
</td>
<td style="vertical-align: top;width: 19px;"><?php echo $user; ?><br>
</td>
<td style="vertical-align: top;width: 50px;"><?php echo "". $ordre_x10 ."<br/ >"; ?><br>
</td>
<td style="vertical-align: top;width: 19px;"><?php echo $fichier2; ?><br>
</td>
<td style="vertical-align: top;width: 19px;"><?php echo $macro; ?><br>
</td>
<td style="vertical-align: top;width: 19px;"><?php echo $execute_par; ?><br>
</td>
</tr>
</tbody>
</table>
<br>
<br>
</body>
</html>
Merci.