当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFileObject::getCsvControl方法代码示例

本文整理汇总了PHP中SplFileObject::getCsvControl方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::getCsvControl方法的具体用法?PHP SplFileObject::getCsvControl怎么用?PHP SplFileObject::getCsvControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplFileObject的用法示例。


在下文中一共展示了SplFileObject::getCsvControl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getEnclosure

 /**
  * @return string
  */
 public function getEnclosure()
 {
     if ($this->enclosure === null) {
         list($delimiter, $this->enclosure) = $this->csvFile->getCsvControl();
     }
     return $this->enclosure;
 }
开发者ID:spryker,项目名称:Library,代码行数:10,代码来源:CsvMeta.php

示例2: SplFileObject

<?php

$file = new SplFileObject(__DIR__ . '/csv.csv');
$file->setFlags(SplFileObject::READ_CSV);
$file->setCsvControl(';');
var_dump($file->getCsvControl());
foreach ($file as $line) {
    var_dump($line);
    exit;
}
开发者ID:ezoic,项目名称:hhvm,代码行数:10,代码来源:csv.php

示例3: SplFileObject

<?php

$obj = new SplFileObject(dirname(__FILE__) . '/SplFileObject_testinput.csv');
var_dump($obj->getCsvControl());
开发者ID:badlamer,项目名称:hhvm,代码行数:4,代码来源:SplFileObject_getCsvControl_basic_001.php

示例4: readFile

 /**
  * read file using phpexcel library
  *
  * @param string $source
  * @return array
  */
 private function readFile($source, $limit = null)
 {
     //load the phpexcel IOFactory class
     include $this->_docRoot . '/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php';
     //prepare the reader,
     try {
         $type = PHPExcel_IOFactory::identify($source);
         if (stripos($type, 'excel') === false && stripos($type, 'csv') === false) {
             $error = ['error' => 'This is not a spreadsheet file.'];
             return $error;
         }
         $reader = PHPExcel_IOFactory::createReader($type);
         //if type is csv (.csv or .txt), find the delimeter
         if ($type == 'CSV') {
             $csvChecker = new SplFileObject($source);
             $csvProperty = $csvChecker->getCsvControl();
             $delimiter = $csvProperty[0];
             $reader->setDelimiter($delimiter);
         }
         $object = $reader->load($source);
     } catch (Exception $e) {
         $error = ['error' => 'I cannot read the file.'];
         return $error;
     }
     //extract the data from the first sheet of the file
     try {
         $sheet = $object->getSheet(0);
         $rows = $sheet->getHighestRow();
         $columns = $sheet->getHighestColumn();
     } catch (Exception $e) {
         $error = ['error' => 'I cannot process the first sheet.'];
         return $error;
     }
     //there should be at least 1 row of data
     if ($rows < 1) {
         $error = ['error' => 'There is not enough data to read.'];
         return $error;
     }
     //read just first 10 rows if it is not for full processing
     $last = $rows;
     $max = !$limit || $rows < $limit + 1 ? $rows : $limit;
     //read the data, metadata into keys and data into data
     $data = [];
     try {
         for ($row = 1; $row <= $max; $row++) {
             $data[] = $sheet->rangeToArray('A' . $row . ':' . $columns . $row, NULL, TRUE, FALSE);
         }
         //add last row if not full processing
         if ($limit && $rows > 10) {
             $data[] = $sheet->rangeToArray('A' . $last . ':' . $columns . $last, NULL, TRUE, FALSE);
         }
     } catch (Exception $e) {
         $error = ['error' => 'I cannot read the data.'];
         return $error;
     }
     if (!is_numeric($columns)) {
         $range = range('A', 'Z');
         $columns = array_search($columns, $range) + 1;
     }
     return ['data' => $data, 'columns' => $columns];
 }
开发者ID:axelcho,项目名称:zend_test,代码行数:67,代码来源:ApiController.php


注:本文中的SplFileObject::getCsvControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。