Bonjour,
J'ai un tableau dans un fichier TXT:
"nom","prenom","email","id"
"moto","toto","moto@toto.com","1255"
"po","to","to@to.com","1254"
"abtoto","ermoto","abtoto@cocooto.com","325"
"cdtoto","tymoto","cdtoto@rororoto.com","25"
Je veux transformer dans un array pour obtenir les variables: $nom, $prenom, $email, $id

Comment je peux donner les bonnes valeurs aux mes variables ci-dessus ?


Alors il faut que j'obtienne quelques choses comme cela :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
$maTableTxt = array(
1 => array('nom' => 'moto', 'prenom' => 'toto', 'email' => 'moto@toto.com', 'id' => '1255'),
2 => array('nom' => 'po', 'prenom' => 'to', 'email' => 'to@to.com', 'id' => '1254'),
3 => array('nom' => 'abtoto', 'prenom' => 'ermoto', 'email' => 'btoto@cocooto.com', 'id' => '25')
//etc....
);
Comment puis-je faire ?

je fais cela mais je n'arrive pas :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
$filetxt = 'test.txt';
$maTableTxt = array();
$lines = file($filetxt, FILE_IGNORE_NEW_LINES);
 
foreach ($lines as $lineNumber => $lineContent){
 
foreach($maTableTxt as $cle => $valeur){
    foreach ($valeur1 as $cle2=>$valeur2){
     $contenuChaqueLine = str_replace ( '"' , '' , $lineContent );
	echo $contenuChaqueLine; // pour voir si cela marche
    }
}
}
Mais echo n'affiche rien.

Où je fais des fautes ?

Merci et bonne soirée

Merci