本文整理汇总了PHP中parseCSV类的典型用法代码示例。如果您正苦于以下问题:PHP parseCSV类的具体用法?PHP parseCSV怎么用?PHP parseCSV使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了parseCSV类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_file
protected function parse_file($file)
{
$csv = new \parseCSV();
$csv->delimiter = ";";
$csv->parse($file);
if ($this->tag_ok) {
$tableHead = "<div class='table-respond'><table><thead><tr><th>Titre</th><th>Album</th></tr></thead><tbody>";
} else {
$tableHead = "<div class='table-respond'><table><thead><tr><th>Titre</th><th>Artiste</th><th>Album</th></tr></thead><tbody>";
}
$tableEnd = "</tbody></table></div>";
$tableBody = "";
foreach ($csv->data as $key => $row) {
$annee = "";
$groupe = "";
if ($this->tag_ok) {
if (isset($row['Groupe']) && strpos(html_entity_decode($row['Groupe']), html_entity_decode($this->tag_name)) !== false) {
if ($row['Année']) {
$annee = "<span class='playlist_year'> (" . $row['Année'] . ")</span>";
}
$tableBody .= "<tr><td>" . $row['Titre'] . "</td><td>" . $row['Album'] . $annee . "</td></tr>";
}
} else {
if ($row['URL']) {
if ($row['Groupe']) {
$groupe = "<a href='" . $row['URL'] . "' title='" . $row['URL'] . "' target='_blank'>" . $row['Groupe'] . "</a>";
} else {
$row['Titre'] = "<a href='" . $row['URL'] . "' title='" . $row['URL'] . "' target='_blank'>" . $row['Titre'] . "</a>";
}
} else {
$groupe = $row['Groupe'];
}
if ($row['Année']) {
$annee = "<span class='playlist_year'> (" . $row['Année'] . ")</span>";
}
$tableBody .= "<tr><td>" . $row['Titre'] . "</td><td>" . $groupe . "</td><td>" . $row['Album'] . $annee . "</td></tr>";
}
}
$ret = $tableHead . $tableBody . $tableEnd;
return $ret;
}
示例2: read
public function read()
{
global $default_charset;
$filePath = $this->getFilePath();
$status = $this->createTable();
if (!$status) {
return false;
}
$csv = new parseCSV();
$csv->delimiter = $this->request->get('delimiter');
$csv->parse($filePath);
$data = $csv->data;
$fieldMapping = $this->request->get('field_mapping');
if (!$this->request->get('has_header')) {
$firstRow = array_keys($data[0]);
array_unshift($data, $firstRow);
}
foreach ($data as $row_data) {
$row_data_index = array_values($row_data);
$mappedData = array();
$allValuesEmpty = true;
foreach ($fieldMapping as $fieldName => $index) {
$fieldValue = $row_data_index[$index];
$mappedData[$fieldName] = $fieldValue;
if ($this->request->get('file_encoding') != $default_charset) {
$mappedData[$fieldName] = $this->convertCharacterEncoding($fieldValue, $this->request->get('file_encoding'), $default_charset);
}
if (!empty($fieldValue)) {
$allValuesEmpty = false;
}
}
if ($allValuesEmpty) {
continue;
}
$fieldNames = array_keys($mappedData);
$fieldValues = array_values($mappedData);
$this->addRecordToDB($fieldNames, $fieldValues);
}
}
示例3: processData
/**
* @param $inputData
* @return MerchantDataListing[]
*/
public function processData($inputData)
{
$inputData = mb_convert_encoding($inputData, "utf-8", "windows-1252");
$csv = new \parseCSV();
//$csv->encoding('Windows-1252', 'UTF-8');
$csv->delimiter = "\t";
$csv->parse($inputData);
$itemList = array();
foreach ($csv->data as $row) {
$item = new MerchantDataListing();
$item->setData($row);
$itemList[] = $item;
}
return $itemList;
}
示例4: csvDataToMemcache
function csvDataToMemcache($csvList, $csvDir, $memIP, $memPort)
{
$memcached = new Memcache();
$memcached->connect($memIP, $memPort);
foreach ($csvList as $key => $value) {
$csvObj = new parseCSV();
$csvObj->auto($csvDir . '/' . $value);
list($fileName, $fileType) = explode('.', $value);
$memcached->set($fileName, $csvObj->data, MEMCACHE_COMPRESSED, 0);
//debug info
//echo "<br/>--------------------------------------------$fileName.csv to memcache-------------------------------------------<br/>";
print_r($memcached->get($fileName));
}
$memcached->close();
echo "success";
}
示例5: getCSV
public static function getCSV($file_path, $limit = false, $offset = false)
{
if (file_exists($file_path) && is_readable($file_path)) {
if (!class_exists('parseCSV')) {
require_once GMEMBER_DIR . '/assets/libs/parsecsv-for-php/parsecsv.lib.php';
}
$csv = new parseCSV();
$csv->encoding('UTF-16', 'UTF-8');
if ($offset) {
$csv->offset = $offset;
}
if ($limit) {
$csv->limit = $limit;
}
$csv->auto($file_path);
return array('titles' => $csv->titles, 'data' => $csv->data);
}
return false;
return array('titles' => array(), 'data' => array());
}
示例6: ImportCsv
function ImportCsv($file_lines, $delims = array(";", ",", "\t"), $quotes = array('"', "'"))
{
function maxChar($chars, $testString)
{
$max_count = 0;
$the_char = count($chars) > 0 ? $chars[0] : " ";
foreach ($chars as $char) {
$new_count = substr_count($testString, $char);
if ($new_count > $max_count) {
$max_count = $new_count;
$the_char = $char;
}
}
return $the_char;
}
$test_line = $file_lines[0];
//
// Detect the most probable delimiter.
//
$delim = maxChar($delims, $test_line);
$quote = maxChar($quotes, $test_line);
//
// Re-Conncat the file-lines
//
$input = implode("\n", $file_lines) . "\n";
//
// Setup and run the parser
//
include "lib/parsecsv.lib.php";
$csv = new parseCSV();
$csv->delimiter = $delim;
$csv->enclosure = $quote;
$csv->file_data =& $input;
$this->data = $csv->parse_string();
//
// Convert the array to addresses
//
$this->convertToAddresses();
}
示例7: index
function index()
{
if (!empty($this->data) && !empty($_POST['submit'])) {
$string = explode(",", trim($this->data['InventoryMaster']['all_item']));
$prsku = $string[0];
if (!empty($string[1])) {
$prname = $string[1];
}
if (!empty($prsku) && !empty($prname)) {
$conditions = array('InventoryMaster.category LIKE' => '%' . $prname . '%', 'InventoryMaster.category LIKE' => '%' . $prsku . '%');
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'InventoryMaster.id ASC', 'conditions' => $conditions);
}
if (!empty($prsku)) {
$conditions = array('OR' => array('InventoryMaster.product_code LIKE' => "%{$prsku}%", 'InventoryMaster.category LIKE' => "%{$prsku}%"));
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'InventoryMaster.id ASC', 'conditions' => $conditions);
}
$this->InventoryMaster->recursive = 1;
$this->set('inventorymasters', $this->paginate());
} else {
if (!empty($_POST['checkid']) && !empty($_POST['exports'])) {
// echo 'dfbgghbfg';die();
$checkboxid = $_POST['checkid'];
App::import("Vendor", "parsecsv");
$csv = new parseCSV();
$filepath = "C:\\Users\\Administrator\\Downloads" . "inventorymasterdb.csv";
$csv->auto($filepath);
$this->set('inventorymasters', $this->InventoryMaster->find('all', array('conditions' => array('InventoryMaster.id' => $checkboxid))));
$this->layout = null;
$this->autoLayout = false;
Configure::write('debug', '2');
} else {
$this->InventoryMaster->recursive = 1;
//$users = $this->InventoryMaster->User->find('list');
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'InventoryMaster.id ASC');
$this->set('inventorymasters', $this->paginate());
}
}
}
示例8: parse_attendee_list
public function parse_attendee_list($csv_text)
{
$csv = new parseCSV();
$csv->delimiter = "\t";
$csv->data = $csv->parse_string($csv_text);
return $csv->data;
}
示例9: csvFileread
function csvFileread($target_file)
{
# include parseCSV class.
require_once 'parsecsv.lib.php';
# create new parseCSV object.
$csv = new parseCSV();
# Parse '_books.csv' using automatic delimiter detection...
$csv->auto("uploads/{$target_file}.csv");
//$csv->auto("abc.csv");
# ...or if you know the delimiter, set the delimiter character
# if its not the default comma...
$csv->delimiter = "\t";
# tab delimited
# ...and then use the parse() function.
// $csv->parse('_books.csv');
# Output result.
echo "hello";
print_r($csv->data);
$i = 0;
foreach ($csv->data as $key => $row) {
print_r($row);
if ($i == 5) {
die;
}
$i++;
}
}
示例10: parseFind
function parseFind($csvFile, $afm, $surname)
{
// init vars
$empOffset = 5;
$anadrData = [];
// parse csv & find employee
$csv = new parseCSV();
$csv->encoding('iso8859-7', 'UTF-8');
$csv->delimiter = ";";
$csv->heading = false;
// find employee T.M.
$csv->offset = $empOffset;
$condition = '8 is ' . $afm . ' AND 1 contains ' . grstrtoupper($surname);
$csv->conditions = $condition;
$csv->parse($csvFile);
$parsed = $csv->data;
// enhanced check of surname (instead of 'contains' in fullname)
if ($parsed) {
$tmp = explode(' ', $parsed[0][1]);
$fileSurname = $tmp[0];
if (strcmp(grstrtoupper($surname), $fileSurname) != 0) {
return ['parsed' => [], 'month' => []];
}
}
// find month
$csv->offset = 1;
$csv->conditions = '19 contains ΜΙΣΘΟΔΟΣΙΑ';
$csv->parse($csvFile);
//$csv->fields =[19];
$data = $csv->data;
$tmp = explode(' ', $data[0][19]);
$month = $tmp[2] . '_' . $tmp[3];
// find anadromika (if any)
$csv->offset = $empOffset;
$csv->conditions = '';
$csv->parse($csvFile);
$data = $csv->data;
$i = $foundFrom = $foundTo = 0;
foreach ($data as $row) {
if (array_key_exists('8', $row) && $afm == $row[8] && !$foundFrom) {
$foundFrom = $i;
}
if ($foundFrom && !$foundTo && array_key_exists('8', $row)) {
if ($row[8] != '' && $row[8] != $afm) {
$foundTo = $i - 1;
}
}
$i++;
}
$tempData = array_slice($data, $foundFrom, $foundTo - $foundFrom + 1);
foreach ($tempData as $line) {
if ($line[10] == 'ΑΝΑΔΡΟΜΙΚΑ') {
$anadrData = $line;
}
}
if (count($anadrData) > 0) {
array_push($parsed, $anadrData);
}
return ['parsed' => $parsed, 'month' => $month];
}
示例11: index
function index()
{
if (!empty($this->data) && !empty($_POST['submit'])) {
$string = explode(",", trim($this->data['EbayenglishListing']['all_item']));
$prsku = $string[0];
if (!empty($string[1])) {
$prname = $string[1];
}
if (!empty($prsku) && !empty($prname)) {
$conditions = array('EbayenglishListing.title LIKE' => '%' . $prname . '%', 'EbayenglishListing.title LIKE' => '%' . $prsku . '%');
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'EbayenglishListing.sku id', 'conditions' => $conditions);
}
if (!empty($prsku)) {
$conditions = array('OR' => array('EbayenglishListing.title LIKE' => "%{$prsku}%", 'EbayenglishListing.sku LIKE' => "%{$prsku}%"));
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'EbayenglishListing.id ASC', 'conditions' => $conditions);
}
$this->set('ebayenglishlistings', $this->paginate());
} else {
if (!empty($_POST['checkid']) && !empty($_POST['exports'])) {
$checkboxid = $_POST['checkid'];
App::import("Vendor", "parsecsv");
$csv = new parseCSV();
$filepath = "C:\\Users\\Administrator\\Downloads" . "ebayenglishlistings.csv";
$csv->auto($filepath);
$this->set('ebayenglishlistings', $this->EbayenglishListing->find('all', array('conditions' => array('EbayenglishListing.id' => $checkboxid))));
$this->layout = null;
$this->autoLayout = false;
Configure::write('debug', '2');
} else {
$this->EbayenglishListing->recursive = 1;
$this->paginate = array('limit' => 1000, 'totallimit' => 2000, 'order' => 'EbayenglishListing.id ASC');
$this->set('ebayenglishlistings', $this->paginate());
}
}
}
示例12: upload
public function upload()
{
ini_set("auto_detect_line_endings", true);
ini_set('memory_limit', '512M');
set_time_limit(600);
require_once ROOT . DS . 'vendor' . DS . 'parsecsv.lib.php';
try {
$numberListTable = TableRegistry::get('NumberLists');
$numberTable = TableRegistry::get('Numbers');
// Generate temp file name
$uploadFullPath = TMP . DS . Text::uuid();
// Move file to temp location
if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadFullPath)) {
throw new \Exception('Cannot copy file to tmp location');
}
$dateTimeUtc = new \DateTimeZone('UTC');
$now = new \DateTime('now', $dateTimeUtc);
// Create new list
$newNumberListData = ['list_name' => $this->request->data['list_name'], 'list_description' => $this->request->data['list_description'], 'create_datetime' => $now, 'update_datetime' => $now];
$numberList = $numberListTable->newEntity($newNumberListData);
$numberListTable->save($numberList);
// Get the data from the file
$csv = new \parseCSV();
$csv->heading = false;
$csv->auto($uploadFullPath);
if (count($csv->data) == 0) {
throw new \Exception('File is empty');
}
$newNumberData = [];
foreach ($csv->data as $row) {
$responseM360 = $this->M360->optInTfn($row[1]);
// $response['d'][] = $responseM360;
$newNumberData = ['number_list_id' => $numberList->number_list_id, 'country_code' => $row[0], 'phone_number' => $row[1], 'opt_in_tfn' => (bool) $responseM360['Message360']['OptIns']['OptIn']['Status'] === 'updated', 'add_datetime' => $now];
$number = $numberTable->newEntity($newNumberData);
$numberTable->save($number);
}
// $numbers = $numberTable->newEntity($newNumberData);
//
// $numberTable->connection()->transactional(function () use ($numberTable, $numbers) {
// foreach ($numbers as $number) {
// $numberTable->save($number, ['atomic' => false]);
// }
// });
unlink($uploadFullPath);
$response['i'] = $newNumberData;
$response['status'] = 1;
} catch (\Excaption $ex) {
$response['status'] = 0;
$response['message'] = $ex->getMessage();
}
$this->set(compact('response'));
$this->set('_serialize', ['response']);
}
示例13: process
/**
* Renders the CSV.
*
* @return void
*/
public function process()
{
$params = $this->gp;
$exportParams = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'exportParams');
if (!is_array($exportParams)) {
$exportParams = t3lib_div::trimExplode(',', $exportParams);
}
//build data
foreach ($params as $key => &$value) {
if (is_array($value)) {
$value = implode(',', $value);
}
if (count($exportParams) > 0 && !in_array($key, $exportParams)) {
unset($params[$key]);
}
$value = str_replace('"', '""', $value);
}
// create new parseCSV object.
$csv = new parseCSV();
$csv->output('formhandler.csv', $data, $params);
die;
}
示例14: saveimport
public function saveimport()
{
$response = array("status" => 0, "msg" => "Gagal simpan data");
include APPPATH . "libraries/parsecsv.lib.php";
// echo "<pre>";
// print_r($_FILES);
// echo "</pre>";
if (isset($_FILES['inputFile']) && !empty($_FILES['inputFile']['name'])) {
$files = $_FILES['inputFile'];
$allowed_extension = array('csv');
$extension = end(explode('.', strtolower($files['name'])));
if (in_array($extension, $allowed_extension)) {
$newname = date('YmdHis') . "_import_cpns.csv";
if (move_uploaded_file($files['tmp_name'], _ROOT . "files/import/{$newname}")) {
if (file_exists(_ROOT . "files/import/{$newname}")) {
$response = array("status" => 0, "msg" => "sukses simpan data");
$destination = _ROOT . "files/import/{$newname}";
$csv = new parseCSV();
$data = $csv->auto($destination);
$datashipping = array();
foreach ((array) $csv->data as $index => $row) {
$save = $this->pengadaan_model->simpanDataCPNSimport($row);
}
$response = array("status" => 1, "msg" => "Sukses import file");
}
}
} else {
$response = array("status" => 0, "msg" => "Ekstensi file harus .csv");
}
}
// echo "<pre>";
// print_r($response);
// echo "</pre>";
echo json_encode($response);
exit;
}
示例15: header
<?php
header('Content-Type: application/json');
require_once '../parsecsv-for-php/parsecsv.lib.php';
$csv = new parseCSV();
$csv->parse('../../../00_ADMIN_CSV_FOLDER/bodytype_service_pricing_minutes.csv');
echo json_encode($csv->data);