本文整理汇总了PHP中parseCSV::unparse方法的典型用法代码示例。如果您正苦于以下问题:PHP parseCSV::unparse方法的具体用法?PHP parseCSV::unparse怎么用?PHP parseCSV::unparse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parseCSV
的用法示例。
在下文中一共展示了parseCSV::unparse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: json_encode
}
/*if(cellProperties.readOnly) {
td.style.opacity = 0.7;
}*/
if(!value || value === '') {
td.style.background = '#EEE';
}
else {
td.style.background = '';
}
}
var data = <?php
echo json_encode($csv->unparse($csv->data, $csv->titles, null, null, null, true));
?>
;
var container = $("#example1");
var hand = container.handsontable({
data: data,
startRows: data.length, //<?php
echo $csv->filelines('../out/test.csv');
?>
,
startCols: <?php
echo count($csv->titles);
?>
,
rowHeaders: true, //turn on 1, 2, 3, ...
示例2: createDBDataSource
private function createDBDataSource($filename, $options, $subdir, $file_path)
{
global $session, $sql;
$query = "INSERT INTO datasources (created_at, updated_at, user_id, name, data_path, file_name, `headers`, `lines`)\n\t\t\t\t VALUES(?, NOW(), ?, ?, ?, ?, ?, ?)";
$stmt = $sql->link->prepare($query);
if (!$stmt) {
die('Invalid query: ' . $sql->link->error);
} else {
$csv = new parseCSV();
$realUserPath = realpath($file_path);
if (filesize($realUserPath) > 0) {
$csv->parse($realUserPath, 0, 10000);
// At max 10000 lines.
$csvDataRows = $csv->unparse($csv->data, $csv->titles, null, null, null, true);
} else {
$csvDataRows = array(array(""));
}
$lines = count($csvDataRows) - 1;
$headers = json_encode($csv->titles);
$subdirSQL = $options['upload_url'] . $subdir;
$time = getCurrentDateTime();
$userID = $this->session->get_user_var('id');
$stmt->bind_param('sissssi', $time, $userID, $filename, $subdirSQL, $filename, $headers, $lines);
$resultFromExec = $stmt->execute();
if ($resultFromExec) {
$affectedRows = $stmt->affected_rows;
}
/* free result */
$stmt->free_result();
$stmt->close();
}
return array("lines" => $lines, "headers" => implode(", ", array_filter($csv->titles)));
}
示例3: readCSV
public function readCSV($inData)
{
$csvData = array('error' => "File Not Found");
$noticeID = $inData['notice_id'];
$user_file_dir = $this->session->get_user_var('file_directory');
$basePath = "../user_files/" . $user_file_dir . "/datasources/";
$realBasePath = realpath($basePath);
$userPath = $basePath . $inData['subdir'] . $inData['file'];
$realUserPath = realpath($userPath);
if ($realUserPath === false || strpos($realUserPath, $realBasePath) !== 0) {
//Is directory Traversal, bad!
$this->outData['data'] = $csvData;
} else {
//Not directory Traversal.
$csv = new parseCSV();
if (filesize($realUserPath) > 0) {
$csv->parse($realUserPath, 0, 10000);
// At max 10000 lines.
$csvDataRows = $csv->unparse($csv->data, $csv->titles, null, null, null, true);
} else {
$csvDataRows = array(array(""));
}
$csvData = array("csv_data" => $csvDataRows, "header_count" => count($csv->titles), "headers" => $csv->titles, "row_count" => count($csvDataRows), "csv_errors" => $csv->error_info);
$this->outData['data'] = $csvData;
}
echo json_encode($csvData);
}