Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 15/12/2010, 19h53   #1
Futur Membre du Club
 
Inscription : mai 2007
Messages : 82
Détails du profil
Informations personnelles :
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : mai 2007
Messages : 82
Points : 19
Points : 19
Par défaut Afficher dans une boucle for le contenu de plusieurs fichiers txt

Bonsoir,

Dans un dossier j'ai des fichiers txt.
Le but est d'afficher une partie du contenu de ces fichiers.

La partie la plus importante ne fonctionne pas

Soit les lignes
Code :
1
2
3
4
5
6
 
echo" propose_par  $propose_par<br>";        //Ligne à afficher
echo" nom_du_sondage $nom_du_sondage<br>";    //Ligne à afficher
echo" nom_du_sondage $serie_questions<br>";    //Ligne à afficher
 
echo'<a href="sondage.php?intro='.$fichier_txt[$i].'&fichier_questions='.$serie_questions.'">Voir le sondage </a> <br />';   //Ligne à afficher
Affichent les valeurs du même fichier (indice 0)


Pourtant la ligne
Code :
1
2
 
echo $ligne_intro[$Nb_ligne_intro]= $uti[1];
affiche bien le contenu de chaque fichiers

Script complet.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
 
// ------------------------------- Met les fichiers dans un array
$listfichier = array();
if ($handle = opendir('intros'))
{
      while (false !== ($fichiers = readdir($handle)))
      {
            if ($fichiers != "." && $fichiers != "..")
            {
            $listfichier[] = $fichiers;
            }
      }
}
$nb_fichier=count($listfichier);
//___________________________________
// ------------------------------- Affiche les fichiers
$Nb_fichier=0;
for($i=0;$i < $nb_fichier;$i++)
{
$fichiers_2="intros/$listfichier[$i]";
$fichiers_3="$listfichier[$i]";
      if ($fichiers_3{0}!=".")
      {
      $fichier_txt[$Nb_fichier]="$fichiers_3";
      $Nb_fichier++;
      }
}
 
// 4 lignes pour verification
echo" Nb_fichier $Nb_fichier <br>";
echo"0   $fichier_txt[0] <br>";
echo"1   $fichier_txt[1] <br>";
echo"2   $fichier_txt[2] <br>";
 
 
$ligne_intro = array();
$Nb_ligne_intro=0;
for($i=0;$i < $Nb_fichier;$i++)
{
      $adresse_intro='intros/'.$fichier_txt[$i];
      echo" adresse_intro $adresse_intro<br>";  // echo verification
      if (!$fp = @fopen($adresse_intro, "r"))
      { echo "Fichier intro introuvable";
        exit;
      }
      while ($zuti = fgets($fp, 2000))
      {
      $uti = explode("#", $zuti);
     echo $ligne_intro[$Nb_ligne_intro]= $uti[1]; // echo verification
       $Nb_ligne_intro++;
      }
      fclose ($fp);
      echo $nom_du_sondage=trim($ligne_intro[1]);  // Echo  pour verification
      echo $propose_par=trim($ligne_intro[3]);      // Echo  pour verification
      echo $presentation_courte=trim($ligne_intro[4]); // Echo  pour verification
      echo $serie_questions=trim($ligne_intro[15]);    // Echo  pour verification
 
      echo" propose_par  $propose_par<br>";        //Ligne à afficher
      echo" nom_du_sondage $nom_du_sondage<br>";    //Ligne à afficher
      echo" nom_du_sondage $serie_questions<br>";    //Ligne à afficher
 
      echo'<a href="sondage.php?intro='.$fichier_txt[$i].'&fichier_questions='.$serie_questions.'">Voir le sondage </a> <br />';   //Ligne à afficher
      echo "$i <br>"; //Echo  pour verification
}
//-----------------------------------
La logique du script? est mauvaise où est l'erreur?

merci de votre aide
anca2 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/12/2010, 08h59   #2
Membre habitué
 
Avatar de Vicrabb
 
Femme Vinciane
Développeur Web
Inscription : novembre 2010
Messages : 66
Détails du profil
Informations personnelles :
Nom : Femme Vinciane
Âge : 29
Localisation : Belgique

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2010
Messages : 66
Points : 100
Points : 100
Code :
1
2
3
echo " propose_par  ".$propose_par."<br>";        //Ligne à afficher
echo " nom_du_sondage ".$nom_du_sondage."<br>";    //Ligne à afficher
echo " nom_du_sondage ".$serie_questions."<br>";    //Ligne à afficher
Essaye ceci pour voir? Sinon, il va falloir vérifier si tu as bien fait les bonnes concaténations dans ton script (je remarque que tu fais du "blaba $variable" mais je ne sais pas si c'est cela qui pose problème).
__________________

Symfony par une débutante - Elgg - PHP

Je suis peut-être diplômée en archéologie mais je ne fouille pas le net pour décrypter le langage SMS, pour lire du code sans la balise du même nom..
"The cake is lie" - Doug Rattman, Portal
Vicrabb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/12/2010, 14h55   #3
Membre chevronné
 
Avatar de christele_r
 
Femme Christele
Inscription : novembre 2009
Messages : 661
Détails du profil
Informations personnelles :
Nom : Femme Christele
Âge : 39
Localisation : France

Informations professionnelles :
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2009
Messages : 661
Points : 690
Points : 690
Bonjour,
Tu dois écrire sous cette forme
Code :
1
2
 
echo" propose_par ".$propose_par."<br>";        //Ligne à afficher
christele_r est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/12/2010, 18h33   #4
Futur Membre du Club
 
Inscription : mai 2007
Messages : 82
Détails du profil
Informations personnelles :
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : mai 2007
Messages : 82
Points : 19
Points : 19
Bonsoir,

Merci mauriser, merci Vicrabb, pour votre aide.
L'erreur venait du fait que je ne remettais pas à 0 l'indice du tableau "$ligne_intro" avant chaque incrémentation de la boucle for.

En dessous du for il fallait mettre $ligne_intro=0;
le bout de code:
Code :
1
2
3
4
5
6
7
8
 
................
$ligne_intro = array();
for($i=0;$i < $Nb_fichier;$i++)
{
      $Nb_ligne_intro=0;
      $adresse_intro='intros/'.$fichier_txt[$i];
.........................
Merci
anca2 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h06.


 
 
 
 
Partenaires

Hébergement Web