當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Reader::setFlags方法代碼示例

本文整理匯總了PHP中League\Csv\Reader::setFlags方法的典型用法代碼示例。如果您正苦於以下問題:PHP Reader::setFlags方法的具體用法?PHP Reader::setFlags怎麽用?PHP Reader::setFlags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在League\Csv\Reader的用法示例。


在下文中一共展示了Reader::setFlags方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parseCsvFile

 /**
  * Parses a csv file into a DataTable.
  *
  * Pass in a filepath to a csv file and an array of column types:
  * ['date', 'number', 'number', 'number'] for example and a DataTable
  * will be built.
  *
  * @access public
  * @since  1.0.0
  * @param  string $filepath    Path location to a csv file
  * @param  array  $columnTypes Array of column types to apply to the csv values
  * @throws \Khill\Lavacharts\Exceptions\InvalidFunctionParam
  * @return \Khill\Lavacharts\DataTable
  */
 public function parseCsvFile($filepath, $columnTypes = null)
 {
     if (Utils::nonEmptyString($filepath) === false) {
         throw new InvalidFunctionParam($filepath, __FUNCTION__, 'string');
     }
     $this->addNewColumns($columnTypes);
     $this->setReader(Reader::createFromPath($filepath));
     $this->reader->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
     $csvColumns = $this->reader->fetchOne();
     foreach ($this->newColumns as $index => $column) {
         if (in_array($column, $this->columnTypes, true) === false) {
             throw new InvalidColumnType($column, Utils::arrayToPipedString($this->columnTypes));
         }
         $this->addColumnFromStrings($columnTypes[$index], $csvColumns[$index]);
     }
     $csvRows = $this->reader->setOffset(1)->fetchAll(function ($row) {
         return array_map(function ($cell) {
             if (is_numeric($cell)) {
                 return $cell + 0;
             } else {
                 return $cell;
             }
         }, $row);
     });
     return $this->addRows($csvRows);
 }
開發者ID:phillipmadsen,項目名稱:datatableplus,代碼行數:40,代碼來源:DataTablePlus.php

示例2: __construct

 /**
  * @param string $filePath  Path to the csv file to read from
  * @param string $delimiter The delimiter for the csv file
  * @param string $enclosure The enclosure for the csv file
  */
 public function __construct($filePath, $delimiter = ',', $enclosure = '"')
 {
     if (!is_file($filePath)) {
         throw new LogicException(sprintf('The file %s does not exist. \\Plum\\PlumCsv\\CsvReader needs an existing csv to work with', $filePath));
     }
     $this->csv = Reader::createFromPath($filePath);
     $this->csv->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
     $this->csv->setDelimiter($delimiter);
     $this->csv->setEnclosure($enclosure);
 }
開發者ID:plumphp,項目名稱:plum-csv,代碼行數:15,代碼來源:CsvReader.php

示例3: testappendStreamFilter

 public function testappendStreamFilter()
 {
     $csv = new Reader(__DIR__ . '/foo.csv');
     $csv->appendStreamFilter('string.toupper');
     $csv->setFlags(SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
     foreach ($csv->getIterator() as $row) {
         $this->assertSame($row, ['JOHN', 'DOE', 'JOHN.DOE@EXAMPLE.COM']);
     }
 }
開發者ID:arvenil,項目名稱:csv,代碼行數:9,代碼來源:CsvTest.php


注:本文中的League\Csv\Reader::setFlags方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。