1
我正在使用PHP
將數據寫入CSV
,但Excel
似乎將我的數據排列成隨機行。下面是代碼:爲什麼Excel以隨機方式(PHP)生成我的CSV?
<?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";
}
?>
這裏是我的意思的例子(請注意,行12我要如何對數據進行組織:
例子:
有人可以幫我這個嗎?