Bonjour,
Je créé des fichiers csv dynamiquement à partir de requêtes mysql.
Le souci que j'ai c'est que un des fichiers csv créé, lu dans excel est sur une seule ligne alors que les autres sont lu correctement. J'ai testé avec "\n" mais sans succès.

Pour exemple voici le script php générant le csv qui est sans problème

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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
$flux_repertoire = '/home/nats/www/csv/';
	$flux_fichier = 'XXXWindilNats.csv'; //
	$flux_categories = array();
	$flux_categories[] = array( 'id' => '21', 'text' => 'Bagues');
	$flux_categories[] = array( 'id' => '22', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '23', 'text' => 'Colliers');
	$flux_categories[] = array( 'id' => '24', 'text' => 'Bracelets');
	$flux_categories[] = array( 'id' => '25', 'text' => 'Boucles d\'Oreilles');
	$flux_categories[] = array( 'id' => '26', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '27', 'text' => 'Piercings');
	$flux_categories[] = array( 'id' => '28', 'text' => 'Chaines de Taille');
	$flux_categories[] = array( 'id' => '29', 'text' => 'Montres');
	$flux_categories[] = array( 'id' => '34', 'text' => 'Medailles');
	$flux_categories[] = array( 'id' => '35', 'text' => 'Elle');
	$flux_categories[] = array( 'id' => '38', 'text' => 'Dolce & Gabbana');
	$flux_categories[] = array( 'id' => '42', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '43', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '44', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '46', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '47', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '48', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '49', 'text' => 'Pendentifs');	
 
// ajout pour avoir tout
	//$flux_categories[] = array( 'id' => '0', 'text' => 'Inconnue');
	$flux_categories[] = array( 'id' => '30', 'text' => 'Bagues de fiançailles');	
	$flux_categories[] = array( 'id' => '31', 'text' => 'Bijoux hommes');	
	$flux_categories[] = array( 'id' => '32', 'text' => 'Bijoux enfants');	
	$flux_categories[] = array( 'id' => '36', 'text' => 'Autres');	
	$flux_categories[] = array( 'id' => '50', 'text' => 'Bijoux Guess');	
	$flux_categories[] = array( 'id' => '52', 'text' => 'Collection Joaillerie');	
	$flux_categories[] = array( 'id' => '56', 'text' => 'Modifiable');	
	$flux_categories[] = array( 'id' => '57', 'text' => 'Bracelets personnalisables');
	$flux_categories[] = array( 'id' => '58', 'text' => 'Mac Douglas');
	$flux_categories[] = array( 'id' => '62', 'text' => 'Promotions');
	$flux_categories[] = array( 'id' => '63', 'text' => 'Hello kitty');
	$flux_categories[] = array( 'id' => '64', 'text' => 'Soldes');
	$flux_categories[] = array( 'id' => '65', 'text' => 'Lamborghini');
	$flux_categories[] = array( 'id' => '67', 'text' => 'Suzette et Benjamin');
	$flux_categories[] = array( 'id' => '68', 'text' => 'Saint Valentin');	
 
	$categorie_csv = 'Mode & Accessoires > Bijoux & Montres > Bijoux > ';
 
 
	for ($i=0; $i < sizeof($flux_categories); $i++) {
		$products_new_query_raw = "select p.products_stock, p.autoriser_achat, p.products_id, p.products_carrot, p.manufacturers_id, p.products_vignette_150, p.products_model, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.sexe, p.couleur from products p, products_description pd, products_to_categories p2c where p.products_carrot=0 and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' AND p2c.products_id=p.products_id AND p2c.categories_id='" . (int)$flux_categories[$i]['id'] . "' order by p.products_date_added DESC, pd.products_name";
		$products_new_query = @mysql_query($products_new_query_raw);
		while ($products_new = @mysql_fetch_array($products_new_query)) {
			$description = html_entity_decode($products_new['products_description']);
			$sqlFabricants = "select manufacturers_name from manufacturers where manufacturers_id='" . (int)$products_new['manufacturers_id'] . "'";
			$resFabricants = @mysql_query($sqlFabricants);
			if (@mysql_num_rows($resFabricants)>0) {
				$rowFabricants = @mysql_fetch_array($resFabricants);
				$fabricant = html_entity_decode($rowFabricants['manufacturers_name']);
			}
			else $fabricant = '';
			$sqlMetal = "SELECT distinct(m.products_metal_name), m2p.products_metal_concentration, m2p.products_metal_poids FROM products_metaux_to_products m2p, products_metaux m WHERE m2p.products_id='" . (int)$products_new['products_id'] . "' AND m2p.products_metal_id=m.products_metal_id AND m.language_id='1'";
			$resMetal = @mysql_query($sqlMetal);
			$j = 0;
			$matiere = '';
			while ($rowMetal = @mysql_fetch_array($resMetal)) {
				$j++;
				$matiere .= ($j>1)?'. ':'';
				$matiere .= html_entity_decode($rowMetal['products_metal_name']);
				if ($rowMetal['products_metal_concentration']>0) $matiere .= ' : ' . $rowMetal['products_metal_concentration'] . ' pour mille, ';
				if ($rowMetal['products_metal_poids']>0) $matiere .= $rowMetal['products_metal_poids'] . ' grammes';
			}
			$sqlPierre = "SELECT p2p.products_pierre_value, p.products_pierre_name FROM products_pierres_to_products p2p, products_pierres p WHERE p2p.products_id='" . (int)$products_new['products_id'] . "' AND p2p.products_pierre_id=p.products_pierre_id AND p.language_id='1'";
			$resPierre = @mysql_query($sqlPierre);
			while($rowPierre = @mysql_fetch_array($resPierre)) {
				$matiere .= '. ';
				$matiere .= html_entity_decode($rowPierre['products_pierre_name']);
				if ($rowPierre['products_pierre_value']>0) $matiere .= ' : ' . $rowPierre['products_pierre_value'] . ' ' . TEXT_CARATS;
			}
			$special_price_query = @mysql_query("select s.specials_new_products_price from specials s where s.products_id = '" . (int)$products_new['products_id'] . "' and status");
			$nb_special_price = @mysql_num_rows($special_price_query);
			if ($nb_special_price>0) {
				$special_price = @mysql_fetch_array($special_price_query);
			}
			$prixAffiche = $products_new['products_price'];
 
			if ($products_new['autoriser_achat']=='1' || $products_new['products_stock']>0) {
 
/*
 
A - Référence annonce [ 40 max. ]
B - Catégorie ( niveau 1 )
C - Titre [ 3 à 60 max. ]
D - Poids / Frais de port
E - Prix de vente TTC en euro
F - Prix d’origine/barré
G - Eco-Participation
H - Etat
I - Quantité
J - Description [ 6 à 3000 ]
K - Code Postal
L - Ville
M - Téléphone
N - Photo 1
O - Photo 2 ( optionnel )
P - Photo 3 ( optionnel )
Q - Photo 4 ( optionnel )
R - Photo 5 ( optionnel )
S - Photo 6 ( optionnel )
T - Code Client
U - Taille
V - Couleur
W - Matière
X - Réf_modele
Y - EAN
Z - ISBN
*/
 
			$flux_content .= $products_new['products_id'] . ';';// A - Référence annonce [ 40 max. ]
			$flux_content .= $categorie_csv . html_entity_decode(ereg_replace(";", ',', $flux_categories[$i]['text'])) . ';';// Catégorie ( niveau 1 )
			$flux_content .= html_entity_decode(ereg_replace(";", ",", $products_new['products_name'])) . ';';// C - Titre [ 3 à 60 max. ]
			$flux_content .= '7 EUR, Offert a partir de 100 EUR d\'achats;';// D - Poids ou Frais de port - > Frais de port
			if ($nb_special_price>0) {
				$flux_content .= ceil($special_price['specials_new_products_price']*1.198392) . ';'; //	E - Prix de vente TTC en euro
				$flux_content .= ceil($products_new['products_price']*1.198392) . ';'; // F - Prix d’origine/barré
			}
			else {
				$flux_content .= ceil($products_new['products_price']*1.198392) . ';'; //	E - Prix de vente TTC en euro
				$flux_content .= ';'; // F - Prix d’origine/barré
			}
			$flux_content .= ';';//	G - Eco-Participation
			$flux_content .= 'NF;';// H - Etat
			$flux_content .= $products_new['products_stock'].';';//I - Quantité
			$flux_content .= html_entity_decode(ereg_replace("\r\n", " ", ereg_replace(";", ",", $description . " " . ereg_replace(";", ",", ereg_replace("&permil;", "pour mille", $matiere))))) . ';';//	Descriptif Long produit	 J - Description [ 6 à 3000 ]
			$flux_content .= ';';//	K - Code Postal
			$flux_content .= ';';//	L - Ville
			$flux_content .= ';';//	M - Téléphone			
			if ($products_new['products_vignette_150']!='') $flux_content .= 'http://www.ysora.com/images/' . $products_new['products_vignette_150'] . ';';// N - Photo 1   ou products_image
			else $flux_content .= ';';// N - Photo 1
			$flux_content .= ';';//	O - Photo 2 ( optionnel )
			$flux_content .= ';';//	P - Photo 3 ( optionnel )
			$flux_content .= ';';//	Q - Photo 4 ( optionnel )
			$flux_content .= ';';//	R - Photo 5 ( optionnel )
			$flux_content .= ';';//	S - Photo 6 ( optionnel )
			$flux_content .= ';';//	T - Code Client
			$flux_content .= ';';//	U - Taille
			if ($products_new['couleur']!='' and $products_new['couleur']!='0') $flux_content .= $products_new['couleur'] . ';';//	V - Couleur
			else $flux_content .= ';';//	V - Couleur
			$flux_content .= ereg_replace("&permil;", "pour mille", $matiere).';';//	W - Matière
			$flux_content .= ';';//	X - Réf_modele
			$flux_content .= ';';//	Y - EAN
			$flux_content .= ';
';//	Z - ISBN			
			}
		}
	}
	$fichier = fopen($flux_repertoire . $flux_fichier, "w");
	fwrite($fichier, $flux_content);
	fclose($fichier);
Voilà le php générant le csv à problème


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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
$flux_repertoire = '/home/nats/www/csv/';
	$flux_fichier = 'xxxguide.csv'; // 
	$flux_categories = array();
	$flux_categories[] = array( 'id' => '21', 'text' => 'Bagues');
	$flux_categories[] = array( 'id' => '22', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '46', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '47', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '48', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '49', 'text' => 'Pendentifs');
	$flux_categories[] = array( 'id' => '23', 'text' => 'Colliers');
	$flux_categories[] = array( 'id' => '24', 'text' => 'Bracelets');
	$flux_categories[] = array( 'id' => '25', 'text' => 'Boucles d\'Oreilles');
	$flux_categories[] = array( 'id' => '26', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '42', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '43', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '44', 'text' => 'Alliances');
	$flux_categories[] = array( 'id' => '34', 'text' => 'Medailles');
	$flux_categories[] = array( 'id' => '27', 'text' => 'Piercings');
	$flux_categories[] = array( 'id' => '28', 'text' => 'Chaines de Taille');
	$flux_categories[] = array( 'id' => '29', 'text' => 'Montres');
	$flux_categories[] = array( 'id' => '35', 'text' => 'Elle');
	$flux_categories[] = array( 'id' => '38', 'text' => 'Dolce & Gabbana');
 
 
	$categorie_csv = 'Mode & Accessoires > Bijoux & Montres > Bijoux > ';
	$flux_content .= 'identifiant_unique;categorie;titre;description;prix;url_produit;url_image;frais_de_port;d3e;disponibilite;ean;prix barre;type_promotion;garantie;delai_de_livraison;marque;';
 
	/*
	Référence,Fabricant|CUP|Nom du produit|Description du produit|Prix du produit (doit s'entendre TTC)|URL produit|URL image|Catégorie|Stock|Description du stock|Frais de port  |Poids | Eco-taxe
 
 
• référence unique du produit
• catégorie du produit
• nom du produit
• description du produit
• prix TTC
• URL de la page du produit
• URL de l’image du produit
 
 
Afin d’améliorer l’affichage de vos offres et pour répondre mieux aux requêtes, nous vous conseillons de compléter votre catalogue avec les informations ci-dessous :
• frais de port
• éco-participation
• disponibilité
• EAN
• prix barré
	*/
 
	for ($i=0; $i < sizeof($flux_categories); $i++) {
		$products_new_query_raw = "select p.products_stock, p.autoriser_achat, p.products_id, p.products_carrot, p.manufacturers_id, p.products_vignette_150, p.products_model, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.sexe from products p, products_description pd, products_to_categories p2c where p.products_carrot=0 and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' AND p2c.products_id=p.products_id AND p2c.categories_id='" . (int)$flux_categories[$i]['id'] . "' order by p.products_date_added DESC, pd.products_name";
		$products_new_query = @mysql_query($products_new_query_raw);
		while ($products_new = @mysql_fetch_array($products_new_query)) {
			$description = html_entity_decode($products_new['products_description']);
			$sqlFabricants = "select manufacturers_name from manufacturers where manufacturers_id='" . (int)$products_new['manufacturers_id'] . "'";
			$resFabricants = @mysql_query($sqlFabricants);
			if (@mysql_num_rows($resFabricants)>0) {
				$rowFabricants = @mysql_fetch_array($resFabricants);
				$fabricant = html_entity_decode($rowFabricants['manufacturers_name']);
			}
			else $fabricant = '';
			$sqlMetal = "SELECT distinct(m.products_metal_name), m2p.products_metal_concentration, m2p.products_metal_poids FROM products_metaux_to_products m2p, products_metaux m WHERE m2p.products_id='" . (int)$products_new['products_id'] . "' AND m2p.products_metal_id=m.products_metal_id AND m.language_id='1'";
			$resMetal = @mysql_query($sqlMetal);
			$j = 0;
			$matiere = '';
			while ($rowMetal = @mysql_fetch_array($resMetal)) {
				$j++;
				$matiere .= ($j>1)?'. ':'';
				$matiere .= html_entity_decode($rowMetal['products_metal_name']);
				if ($rowMetal['products_metal_concentration']>0) $matiere .= ' : ' . $rowMetal['products_metal_concentration'] . ' pour mille, ';
				if ($rowMetal['products_metal_poids']>0) $matiere .= $rowMetal['products_metal_poids'] . ' grammes';
			}
			$sqlPierre = "SELECT p2p.products_pierre_value, p.products_pierre_name FROM products_pierres_to_products p2p, products_pierres p WHERE p2p.products_id='" . (int)$products_new['products_id'] . "' AND p2p.products_pierre_id=p.products_pierre_id AND p.language_id='1'";
			$resPierre = @mysql_query($sqlPierre);
			while($rowPierre = @mysql_fetch_array($resPierre)) {
				$matiere .= '. ';
				$matiere .= html_entity_decode($rowPierre['products_pierre_name']);
				if ($rowPierre['products_pierre_value']>0) $matiere .= ' : ' . $rowPierre['products_pierre_value'] . ' ' . TEXT_CARATS;
			}
			$special_price_query = @mysql_query("select s.specials_new_products_price from specials s where s.products_id = '" . (int)$products_new['products_id'] . "' and status");
			$nb_special_price = @mysql_num_rows($special_price_query);
			if ($nb_special_price>0) {
				$special_price = @mysql_fetch_array($special_price_query);
			}
			$prixAffiche = $products_new['products_price'];
			if ($products_new['autoriser_achat']=='1' || $products_new['products_stock']>0) {
 
			$flux_content .= $products_new['products_id'] . ';';//Référence Modèle	
			$flux_content .= $categorie_csv . html_entity_decode(ereg_replace(";", ',', $flux_categories[$i]['text'])) . ';';//categ
			$flux_content .= html_entity_decode(ereg_replace(";", ",", $products_new['products_name'])) . ';';//Titre de l'article
			$flux_content .= html_entity_decode(ereg_replace("\r\n", " ", ereg_replace(";", ",", $description . " " . ereg_replace(";", ",", ereg_replace("&permil;", "pour mille", $matiere))))) . ';';//	Descriptif Long produit
			if ($nb_special_price>0) {//	Prix d'origine
				$flux_content .= ceil($special_price['specials_new_products_price']*1.198392) . ';';
			}
			else {
				$flux_content .= ceil($products_new['products_price']*1.198392) . ';';
			}
			$flux_content .= 'http://www.ysora.com/product_info.php?xtor=AL-68&products_id=' . $products_new['products_id'] . ';';
			if ($products_new['products_vignette_150']!='') $flux_content .= 'http://www.ysora.com/images/' . $products_new['products_vignette_150'] . ';';//	url Image vue 1
			else $flux_content .= ';';//	url Image vue 1
			$flux_content .= '7 EUR, Offert a partir de 100 EUR d\'achats;';//	port
			$flux_content .= '0;';//	éco-participation
			$flux_content .= '0;';//	disponible
			$flux_content .= $products_new['products_model'] . ';';//	EAN		
			if ($nb_special_price>0) {//	prix barré
				$flux_content .= ceil($products_new['products_price']*1.198392) . ';';
			}
			else {
				$flux_content .= ';';
			}
			if ($nb_special_price>0) {//	type_promotion
				$flux_content .= '1;';
			}
			else {
				$flux_content .= '0;';
			}		
 
			}
		$flux_content .= '2;';// garantie
		$flux_content .= '72 heures;';// delais livraison	
		if ($fabricant['manufacturers_name'] !='')
		$flux_content .= html_entity_decode($fabricant['manufacturers_name']) . ';'; //marque
		else 
		$flux_content .= 'Bijouterie Ysora;';// produit sans marque
 
		}
 
	}
 
	$fichier = fopen($flux_repertoire . $flux_fichier, "w");
	fwrite($fichier, $flux_content);
	fclose($fichier);
	echo "traitement terminé";
Je sais les codes sont longs mais ça fait trois jours que je suis dessus et j'ai peur de ne plus avoir le recul nécessaire pour toutes analyses.

Merci d'avance pour votre aide et compréhension