PHP脚本没有图形化的一面
我这里有一段代码,是我从互联网上下载的,它应该把数据从mySQL数据库导出到excel文件中。 问题是我该怎么触发这个?没有图形化的一面,没有触发脚本的按钮,什么都没有。 我怎样才能让它工作PHP脚本没有图形化的一面,php,html,user-interface,Php,Html,User Interface,我这里有一段代码,是我从互联网上下载的,它应该把数据从mySQL数据库导出到excel文件中。 问题是我该怎么触发这个?没有图形化的一面,没有触发脚本的按钮,什么都没有。 我怎样才能让它工作 <?PHP // Original PHP code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. include('config.
<?PHP
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
include('config.php');
function cleanData(&$str)
{
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
// filename for download
$filename = "website_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
$result = pg_query("SELECT * FROM norse5_proov ORDER BY id") or die('Query failed!');
while(false !== ($row = pg_fetch_assoc($result))) {
if(!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\r\n";
}
exit;
?>
以下是一些在商业应用程序中适用于我的代码
if($_REQUEST["EXCEL"]){
header("Content-Type: application/excel");
header("Content-Disposition: attachment; FileName=assets.xls");
header("Cache-Control: private");
header("Content-Length: ".strLen($data));
echo $data;
exit;
}
$data是以制表符分隔的文本,但excel标题会打开excel并导入文本尝试学习php而不是复制/粘贴。学习一些html,我能很好地理解代码。我精通HTML和CSS,但PHP是编程高手……请注意最新版本的MS Excel在文件扩展名与实际文件格式不匹配时发出的警告