首先在根目录创建一个PHP文件,然后将以下代码粘贴进去,文件名自拟。
<?php/*** 导出keywords表数据*/require_once(dirname(__FILE__)."/dede/include/common.inc.php");$sql = "SELECT arc.id, arc.title, arc.description, arc.keywords, tp.typedir FROM `dede_archives` arc,`dede_arctype` tp WHERE arc.typeid = tp.id";$dsql->SetQuery($sql);$dsql->Execute();$list = [];while($row = $dsql->GetArray()){$list[] = $row;}// 下载set_time_limit(0);ini_set('memory_limit', '256M');//下载csv的文件名$fileName = 'dede_tdk.csv';//设置header头header('Content-Description: File Transfer');header('Content-Type: application/vnd.ms-excel');header('Content-Disposition: attachment; filename="' . $fileName . '"');header('Expires: 0');header('Cache-Control: must-revalidate');header('Pragma: public');//打开php数据输入缓冲区$fp = fopen('php://output', 'a');$heade = ['id', 'url', 'title', 'description', 'keywords'];//将数据编码转换成GBK格式mb_convert_variables('GBK', 'UTF-8', $heade);//将数据格式化为CSV格式并写入到output流中fputcsv($fp, $heade);//如果在csv中输出一个空行,向句柄中写入一个空数组即可实现foreach ($list as $value) {//将数据编码转换成GBK格式mb_convert_variables('GBK', 'UTF-8', $value);$data['id'] = $value['id'];$data['url'] = 'https://www.zxjpjmd.com' . $value['typedir'] . '/' . $value['id'] . '.html';$data['title'] = $value['title'];$data['description'] = $value['description'];$data['keywords'] = $value['keywords'];fputcsv($fp, $data);//将已经存储到csv中的变量数据销毁,释放内存unset($value);}//关闭句柄fclose($fp);
