本文整理汇总了PHP中array2csv函数的典型用法代码示例。如果您正苦于以下问题:PHP array2csv函数的具体用法?PHP array2csv怎么用?PHP array2csv使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array2csv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: csvFromKeyedArray
function csvFromKeyedArray($keyedArray, $filename = NULL)
{
$headers = array_keys($keyedArray[0]);
$headerRow = str_putcsv($headers);
$csvBody = array2csv($keyedArray);
return "{$headerRow}\n{$csvBody}";
}
示例2: getcsv
function getcsv($array, $download = "")
{
if ($download != "")
{
header('Content-Type: application/csv');
header('Content-Disposition: attachement; filename="' . $download . '"');
echo array2csv($array);
exit;
}
die;
}
示例3: download
function download()
{
$data = filter_forwarded_data($this);
$this->load->helper('report');
$report = $this->_report->report_to_array($data['t']);
# download CSV
if ($data['t'] == 'download_csv') {
send_download_headers("file_" . strtotime('now') . ".csv");
echo array2csv($report);
die;
} else {
if ($data['t'] == 'download_pdf') {
$this->load->model('_file');
$reportType = $this->native_session->get('__report_type') ? $this->native_session->get('__report_type') : 'procurement_plan_tracking';
$this->_file->generate_pdf(generate_report_html($report, $reportType), UPLOAD_DIRECTORY . 'file_' . strtotime('now') . '.pdf', 'download', array('size' => 'A4', 'orientation' => 'landscape'));
}
}
}
示例4: fputcsv
$headers[] = 'pos_start';
$headers[] = 'pos_end';
$headers[] = 'description';
$headers[] = 'coref_group';
$headers[] = 'author';
$headers[] = 'date_added';
fputcsv($df, $headers);
foreach ($array as $row) {
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}
function download_send_headers($filename)
{
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
download_send_headers("coref_export_" . date("Y-m-d") . ".csv");
echo array2csv($qbc->getAllCorefs());
die;
示例5: header
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
// ****************************************************************
// access check
include "includes/startloggedinadmin.inc.php";
require_once "classes/constants.class.php";
//require_once "classes/template.class.php";
//require_once "classes/templatehelper.class.php";
require_once "classes/db.class.php";
require_once "classes/sessionhelper.class.php";
//require_once "classes/jswriter.class.php";
//require_once "classes/validationhelper.class.php";
require_once "classes/bookingshelper.class.php";
if (!SessionHelper::isMaster()) {
die("You don't belong here!");
}
$db = new Db();
$q = "\nSELECT \n\tb.first_name AS first_name,\n\tb.last_name AS last_name,\n\tb.email AS email\nFROM\n\tbookings b\nGROUP BY \n\temail\nORDER BY \n\temail\n";
//pr($q); // exit();
$rows = $db->getRowsByQuery($q);
$rows2 = array();
foreach ($rows as $row) {
$rows2[] = array("name" => $row["first_name"], "surname" => $row["last_name"], "email" => $row["email"]);
}
unset($rows);
//pr($rows2); exit;
// ********************* export it now *****************9
download_send_headers("aps_emails_export_" . date("Y-m-d") . ".csv");
echo array2csv($rows2);
die;
示例6: fputcsv
}
}
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}
function download_send_headers($filename)
{
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
if (isset($_POST['csv_download']) && $options['settings']['is_key_valid']) {
download_send_headers("data_export_" . date("Y-m-d") . ".csv");
echo array2csv($options['feeds']);
die;
}
/* echo "<pre>";
print_r($options);
exit; */
示例7: array2csv
function array2csv(array &$array, $titles)
{
if (count($array) == 0) {
return null;
}
$df = fopen("file1.csv", 'w');
fwrite($df, "");
fputcsv($df, $titles, ';');
foreach ($array as $row) {
fputcsv($df, $row, ';');
}
fclose($df);
}
$titles = array("Категория", "Значение");
$data = array(array('Сумма всех посещений', $arrow[0]), array('Посещения библиотеки', $arrow[1]), array('Сумма Справок', $arrow[0]), array('Количество консультаций', $docs_array[3]), array('Удаленное обслуживание', $docs_array[2]), array('Искандэр', $docs_array[0]), array('Кипарис', $docs_array[1]), array('Правовые справочные системы', $docs_array[2]), array('Консультант+:', $arrow[3]), array('Правовые Базы:', $arrow[4]));
array2csv($data, $titles);
if (isset($_POST['export_csv'])) {
file_force_download('file1.csv');
}
?>
<form action="" method="post">
<input type="submit" name="export_csv" value="Скачать" class="form-control" id="save">
</form>
<input type="button" value="Печать" class="form-control" id="print" >
</form>
<script>
$("#print").on('click', function () {
示例8: download_send_headers
break;
case 'pdf_format':
$format_extn = '.pdf';
break;
case 'text_format':
default:
$format_extn = '.txt';
break;
}
//pa($array_var);
download_send_headers("data_export_" . date("Y-m-d") . "{$format_extn}", $download_format);
//download_send_headers("data_export_" . date("Y-m-d") . ".html");
switch ($download_format) {
case 'excel_format':
if (is_array($array_var)) {
echo array2csv($array_var);
}
break;
case 'xml_format':
if (is_array($array_var)) {
echo array2xml($array_var);
}
break;
case 'worddoc_format':
if (is_array($array_var)) {
echo array2worddoc($array_var);
}
break;
case 'pdf_format':
if (is_array($array_var)) {
echo array2pdf($array_var);
示例9: switch
$im->Subject = 'Search Result';
$im->Body = 'Please find attached the search result';
switch ($_GET['email_format'][0]) {
case 'text_format':
$report_op = array2text($search_class_array_all);
$file_name = date("Y-m-d") . '_' . $class . '_report_output.txt';
break;
case 'pdf_format':
$report_op = array2pdf($search_class_array_all);
$file_name = date("Y-m-d") . '_' . $class . '_report_output.pdf';
break;
case 'xml_format':
$report_op = array2xml($search_class_array_all);
$file_name = date("Y-m-d") . '_' . $class . '_report_output.txt';
break;
case 'worddoc_format':
$report_op = array2worddoc($search_class_array_all);
$file_name = date("Y-m-d") . '_' . $class . '_report_output.doc';
break;
default:
$report_op = array2csv($search_class_array_all);
$file_name = date("Y-m-d") . '_' . $class . '_report_output.csv';
break;
}
$im->addStringAttachment($report_op, $file_name);
$im->ino_sendMail();
}
include_once __DIR__ . '/../template/json_search_template.inc';
echo '</div>';
$dbc->confirm();
}
示例10: woocommerce_top_sellers
//.........这里部分代码省略.........
echo '<td>' . $rrp1 . '</td>';
echo '<td width=15%><span>' . esc_html($sales) . '</span></td>';
echo '<td>' . $rrp2 . '</td>';
echo '<td>' . $rrp6 . '</td>';
echo '<td>' . $rrp7 . '</td>';
echo '<td>' . $rrp8 . '</td>';
echo '<td>' . $rrp9 . '</td>';
echo '<td>' . $rrp10 . '</td>';
echo '<td>' . $rrp11 . '</td>';
echo '<td>' . $rrp12 . '</td>';
echo '</tr>';
$tt = esc_html($sales);
$bb1[] = array($skuu, $rrp4, $rrp, $rrp1, $rrp2, $rrp6, $rrp7, $rrp8, $rrp9, $rrp10, $rrp11, $rrp12);
//$bb[]=array($rrp4,$rrp,$rrp1,(esc_html( $sales )),$rrp2,$rrp6,$rrp7,$rrp8,$rrp9,$rrp10,$rrp11);
$y = 0;
if ($a == 1) {
$bb[] = array($rrp4, $rrp, $rrp1, esc_html($sales), $rrp2, $rrp6, $rrp7, $rrp8, $rrp9, $rrp10, $rrp11, $rrp12);
} else {
for ($x = 0; $x < count($bb); $x++) {
if (trim($rrp4) == $bb[$x][0]) {
$y = 1;
$bb[$x][3] = $bb[$x][3] + $tt;
$bb[$x][4] = $bb[$x][4] + $rrp2;
$bb[$x][13] = $bb[$x][13] . ',' . $product_title;
$bb[$x][12] = $bb[$x][12] . '+' . $sales;
}
}
if ($y != 1) {
$bb[] = array($rrp4, $rrp, $rrp1, esc_html($sales), $rrp2, $rrp6, $rrp7, $rrp8, $rrp9, $rrp10, $rrp11, $rrp12);
}
}
$a++;
}
function array2csv($input_array, $delimiter = ',', $enclosure = '"', $force_enclose = false, $crlf = "\r\n")
{
// filter incoming params
if (!is_array($input_array)) {
return false;
}
$delimiter = @trim($delimiter);
$enclosure = @trim($enclosure);
$force_enclose = @(bool) $force_enclose;
$crlf = @(string) $crlf;
// transform array into 2-d array of strings
if (!is_array(array_shift(array_values($input_array)))) {
$input_array = array($input_array);
}
foreach (array_keys($input_array) as $k) {
if (!is_array($input_array[$k])) {
return false;
}
foreach ($input_array[$k] as $j => $value) {
$input_array[$k][$j] = @(string) $value;
}
}
// process input array
// RFC-compatible CSV (requires PHP 5)
if (false === $force_enclose) {
if (!function_exists('fputcsv')) {
return false;
}
// taken from http://www.php.net/manual/ru/function.fputcsv.php
$csv = fopen('php://temp/maxmemory:' . 1048576, 'r+');
// try to allocate 1 MB of memory
if (false === $csv) {
return false;
示例11: exportData
function exportData()
{
function build_sorter($key)
{
return function ($a, $b) use($key) {
return strnatcmp($a->{$key}, $b->{$key});
};
}
$permits = $this->session->userdata();
$prod = array_merge($permits['foda']['view'], $permits['metaP']['view']);
$finan = array_merge($permits['valorF']['view'], $permits['metaF']['view']);
if (count($prod) + count($finan) <= 0) {
redirect('inicio');
}
$this->form_validation->set_rules('graphic', 'Gráfico', 'required|numeric|greater_than_equal_to[0]');
$this->form_validation->set_rules('all', 'Todo', 'required|numeric|in_list[0,1]');
if (!$this->form_validation->run()) {
redirect('inicio');
}
$graphic = $this->input->post('graphic');
$all = strcmp($this->input->post('all'), "1") == 0 ? true : false;
$graphic = $all ? $this->Dashboard_model->getAllGraphicData($graphic) : $this->Dashboard_model->getGraphicData($graphic);
$key = $all ? 'year' : 'x';
$data = [];
$metric = (object) ["x_name" => "Año"];
foreach ($graphic->series as $serie) {
$prename = $all || strcmp($serie->aggregation, "") == 0 ? "" : $serie->aggregation . " de ";
$metorg = $this->Metorg_model->getMetOrg(['id' => [$serie->metorg]])[0];
$metric = $this->Metrics_model->getMetric(['id' => [$metorg->metric]])[0];
foreach ($serie->values as $value) {
if (!key_exists('target', $value)) {
continue;
}
$value->metric = $prename . $serie->name . " de " . $serie->org;
$data[] = $value;
}
}
$graphic->x_name = $all ? $metric->x_name : $graphic->x_name;
$title = $graphic->title . " Periodo (" . $graphic->min_year . " - " . $graphic->max_year . ")";
usort($data, build_sorter($key));
download_send_headers(str_replace(" ", "_", $title) . "_" . date("d-m-Y") . ".csv");
echo array2csv($data, $title, $graphic->x_name, $graphic->y_name, $all);
return;
}
示例12: session_start
<?php
session_start();
error_reporting(0);
set_time_limit(0);
require 'scrap-function.php';
if ($_POST['save']) {
echo array2csv($_SESSION['emails'], 'sample.csv');
unset($_SESSION['emails']);
echo '<h3 style="color:#00FF00">Your data saved . Close this popup window </h3>';
}
?>
<form method="POST">
<input type="submit" name="save" value="Save" /> |
</form>
示例13: gmdate
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
function array2csv(array &$array)
{
if (count($array) == 0) {
return null;
}
ob_start();
$df = fopen("php://output", 'w');
foreach ($array as $row) {
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}
// echo "<pre>";
//print_r($metaArray);
download_send_headers("meta_data_export_" . date("Y-m-d-H-i-s") . ".csv");
echo array2csv($metaArray);
die;
示例14: example
function example()
{
try {
$DB = new MxOptix();
global $app;
$body = $app->request()->getBody();
$body = json_decode($body, true);
// print_r($body);
$DB->setQuery($body['query']);
$results = null;
oci_execute($DB->statement);
oci_fetch_all($DB->statement, $results, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
// print_r($results);
// print_r($results);
echo array2csv($results);
$DB->close();
} catch (Exception $e) {
$DB->close();
echo 'Caught exception: ' . $e->getMessage() . "\n";
}
}
示例15: array2csv
/**
* Convert an array into a CSV string
*
* @param array $array
* @return string
*/
function array2csv(array $array)
{
$lines = array();
foreach ($array as $val) {
$lines[] = is_array($val) ? array2csv($val) : '"' . str_replace('"', '""', $val) . '"';
}
return implode(",", $lines);
}