Ich schreibe Daten in eine CSV
mit PHP
, aber Excel
scheint meine Daten in zufällige Reihen anzuordnen. Hier ist der Code:Warum generiert Excel meine CSV in zufälliger Weise (PHP)?
<?php
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="Titles.csv"');
// do not cache the file
header('Pragma: no-cache');
header('Expires: 0');
// create a file pointer connected to the output stream
$file = fopen('php://output', 'w');
$keywords = $_POST['keywords'];
$copytext = $_POST['copytext'];
$brand = $_POST['brand'];
$KeywordArray = explode(',', $keywords);
$CopyTextArray = explode(',', $copytext);
$BrandArray = explode(',', $brand);
$RandomCopy = array_rand($CopyTextArray, 3);
$RandomBrand = array_rand($BrandArray, 3);
echo "Keyword,Title\n";
foreach ($KeywordArray as $element) {
echo $element.",";
echo $element." ";
echo $CopyTextArray[$RandomCopy[rand(0,2)]]." ";
echo $BrandArray[$RandomBrand[rand(0,2)]]."\n";
}
?>
Und hier ist ein Beispiel dafür, was ich meine (bitte beachten Sie, dass die Zeile 12 ist, wie ich die Daten organisiert werden soll:
Beispiel:
Könnte jemand bitte mir dabei helfen?