我想導出我的聯繫電子郵件,存儲在MySQL數據庫與腳本。 我需要導出我的電子郵件在CSV文件。從php導出電子郵件與php,但出口我所有的PHP頁面
但是,當頁面重新加載,文件正在下載並進入這個文件我有我所有的PHP頁面!
<?php
if(IsSet($_POST['export_test'])){
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('E-mail'));
// fetch the data
$string = "SELECT Email FROM address";
$query = mysql_query($string);
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($query)) fputcsv($output, $row);
}
?>
在data.csv我可以看到我的所有網頁
(<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<title>Test</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700,300' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="icon/advancedsettings.png" type="image/x-icon" />.....)
謝謝
'die(); // while while循環之後 – Steve
你有一個{之後缺少 – Mihai
@Mihai花括號不需要單線循環結構 – Steve