在参数中传递字符串以在PHP中创建.csv
我想通过在原始.csv结尾添加一个字符串来编辑.csv,然后下载用PHP创建的新.csv 我的代码是:在参数中传递字符串以在PHP中创建.csv,php,string,csv,Php,String,Csv,我想通过在原始.csv结尾添加一个字符串来编辑.csv,然后下载用PHP创建的新.csv 我的代码是: <?php header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0"); $file = fopen("csv.csv","r"); $list = ar
<?php
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
$file = fopen("csv.csv","r");
$list = array();
while(! feof($file))
{
$list[] = (fgetcsv($file));
}
fclose($file);
$CSV = 'name5:SEPARATOR1:town5:SEPARATOR2:name6:SEPARATOR1:town6:SEPARATOR2:name6:SEPARATOR1:town6:SEPARATOR2:';
$csv_array = explode(":SEPARATOR2:", $CSV);
for($i=0;$i<count($csv_array)-1;$i++){
$temp = explode(":SEPARATOR1:", $csv_array[$i]);
$list[] = array($temp[0],$temp[1]);
}
$list = array_filter($list);
outputCSV($list);
function outputCSV($list) {
$output = fopen("php://output", "w");
foreach ($list as $row) {
fputcsv($output, $row);
}
fclose($output);
}
?>
但是我希望从另一个页面动态创建字符串$CSV。
可以使用GET函数,但$CSV太长。
我尝试使用ajax,但没有成功。
有人有什么想法吗?是来自您的域的文件,您不能只包含它吗。否则,试试看卷发,但我不明白它怎么能帮到我,我太笨了,在$_课程中,它非常简单!!!!!!