我正在尝试创建一个wordpress插件,我需要从数据库中导出一些东西。
<?php
ob_start();
global $wpdb;
$statements = $wpdb->get_results( "SELECT * FROM wp_paypal_statements ORDER BY id DESC" );
if (isset($_POST["export"]))
{
ob_end_clean();
$csv = "User ID, PayPal Email, Amount \n";//Column headers
foreach ($statements as $record)
{
$csv .= $record->id . ',' . $record->paypal_email. ',' . $record->amount . "\n"; //Append data to csv
}
$csv_handler = fopen("php://output", 'w');
fwrite ($csv_handler,$csv);
fclose ($csv_handler);
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
exit();
}
我正在获取该文件的html源代码。例如:
<!DOCTYPE html>
<!--[if IE 8]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8 wp-toolbar" lang="en-US">
<![endif]-->
<!--[if !(IE 8) ]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" class="wp-toolbar" lang="en-US">
<!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> ‹ WP Plugin Factory London — WordPress</title>
<script type="text/javascript">
这就是我的代码看起来如何,我没有看到这里有什么问题。有帮助吗?谢谢!