Bonjour,
J'ai un tableau dans un fichier TXT:
Je veux transformer dans un array pour obtenir les variables: $nom, $prenom, $email, $id"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"
Comment je peux donner les bonnes valeurs aux mes variables ci-dessus ?
Alors il faut que j'obtienne quelques choses comme cela :
Comment puis-je faire ?
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.... );
je fais cela mais je n'arrive pas :
Mais echo n'affiche rien.
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 } } }
Où je fais des fautes ?
Merci et bonne soirée
Merci
Partager