Bonjour,
Mon code pour lire un bout d'un fichier fonctionne bien mais j'ai un probleme de notice que je n'arrive pas à enlever.

Merci d'avance.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
<?php
// le fichier
$fichier='DUYCK.txt';
// declaration 
$typeProduit[]='';
$nomParcelle[]='';
$nomProduit[]='';
$date[]='';
$quantite[]='';
$cpt = 0;
// ouverture du fichier
$fp=fopen($fichier,'r');
 
while (!feof($fp)) {
// lecture et decoupage des lignes à chaque ;
$position=explode(";",fgets($fp,255));
// $position dans la ligne commence à zero
 
$nomParcelle[$cpt].=$position[0];
$typeProduit[$cpt].=$position[1];
$nomProduit[$cpt].=$position[2];
$date[$cpt].=$position[3];
$quantite[$cpt].=$position[4];
$cpt = $cpt + 1;  
}
 
// fermeture du fichier
fclose($fp);
// affichage des villes
print $nomParcelle[0].'<br />';
print $typeProduit[0].'<br />';
print $nomProduit[0].'<br />';
print $date[0].'<br />';
print $quantite[0].'<br />';
?>
Résultat :
Notice: Undefined offset: 1 in C:\wamp\www\Site\DuyckPC.php on line 21

Notice: Undefined offset: 1 in C:\wamp\www\Site\DuyckPC.php on line 22

Notice: Undefined offset: 1 in C:\wamp\www\Site\DuyckPC.php on line 22

Notice: Undefined offset: 2 in C:\wamp\www\Site\DuyckPC.php on line 23

Notice: Undefined offset: 1 in C:\wamp\www\Site\DuyckPC.php on line 23

Notice: Undefined offset: 3 in C:\wamp\www\Site\DuyckPC.php on line 24

Notice: Undefined offset: 1 in C:\wamp\www\Site\DuyckPC.php on line 24

Notice: Undefined offset: 4 in C:\wamp\www\Site\DuyckPC.php on line 25

Notice: Undefined offset: 1 in C:\wamp\www\Site\DuyckPC.php on line 25