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


PHP Reader::createFromString方法代码示例

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


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

示例1: import

 /**
  * 
  */
 public function import($data, Event $event)
 {
     $csv = Reader::createFromString(trim($data));
     $csv->setDelimiter(';');
     // get startgroups at first
     $groups = new Map();
     foreach ($csv->fetchColumn(0) as $name) {
         if (!$groups->has($name)) {
             $startgroup = $this->getStartgroup($name);
             $startgroup->setEvent($event);
             $groups->set($name, $startgroup);
         }
     }
     $id = 0;
     foreach ($csv as $row) {
         $id++;
         $routine = $this->getRoutine($id);
         $group = $groups->get($row[0]);
         $judges = (count($row) - 1) / 3;
         for ($j = 1; $j <= $judges; $j++) {
             $score = new PerformanceScore();
             $score->setRoutine($routine);
             $score->setJudge($group->getPerformanceJudge($j));
             $score->setExecution($row[($j - 1) * 3 + 1]);
             $score->setChoreography($row[($j - 1) * 3 + 2]);
             $score->setMusicAndTiming($row[($j - 1) * 3 + 3]);
             $score->setTotal($row[($j - 1) * 3 + 1] + $row[($j - 1) * 3 + 2] + $row[($j - 1) * 3 + 3]);
             $routine->addPerformanceScore($score);
         }
         $group->addRoutine($routine);
         $group->save();
     }
     $event->save();
 }
开发者ID:iuf,项目名称:junia,代码行数:37,代码来源:SchubertImporter.php

示例2: readCSV

 protected function readCSV()
 {
     $csvObj = Reader::createFromString($this->readFile(static::IMPORT_FILE));
     $csvObj->setDelimiter(',');
     $results = $csvObj->fetchAssoc();
     return $results;
 }
开发者ID:firegento,项目名称:FireGento_FastSimpleImport2_Demo,代码行数:7,代码来源:ImportCsv.php

示例3: createImportEntries

 /**
  * Run the actual import
  *
  * @return Collection
  */
 public function createImportEntries() : Collection
 {
     $config = $this->job->configuration;
     $content = $this->job->uploadFileContents();
     // create CSV reader.
     $reader = Reader::createFromString($content);
     $reader->setDelimiter($config['delimiter']);
     $start = $config['has-headers'] ? 1 : 0;
     $results = $reader->fetch();
     Log::notice('Building importable objects from CSV file.');
     foreach ($results as $index => $row) {
         if ($index >= $start) {
             $line = $index + 1;
             Log::debug('----- import entry build start --');
             Log::debug(sprintf('Now going to import row %d.', $index));
             $importEntry = $this->importSingleRow($index, $row);
             $this->collection->put($line, $importEntry);
             /**
              * 1. Build import entry.
              * 2. Validate import entry.
              * 3. Store journal.
              * 4. Run rules.
              */
             $this->job->addTotalSteps(4);
             $this->job->addStepsDone(1);
         }
     }
     Log::debug(sprintf('Import collection contains %d entries', $this->collection->count()));
     Log::notice(sprintf('Built %d importable object(s) from your CSV file.', $this->collection->count()));
     return $this->collection;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:36,代码来源:CsvImporter.php

示例4: fetch

 public function fetch(Connector $connector, EncapsulatedOptions $options = null)
 {
     $csv = $connector->fetch('http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv');
     $reader = Reader::createFromString($csv);
     foreach ($reader->fetchAssoc() as $row) {
         (yield $row);
     }
 }
开发者ID:Provider,项目名称:IANA,代码行数:8,代码来源:IanaPortNumbers.php

示例5: __construct

 public function __construct($data)
 {
     if (is_string($data)) {
         $this->csv = Reader::createFromString($data);
     } else {
         throw new InvalidArgumentException('CsvParser only accepts (string) [csv] for $data.');
     }
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:8,代码来源:CsvParser.php

示例6: getReader

 /**
  * @param string $data
  * @return Reader
  */
 protected function getReader($data)
 {
     $csv = Reader::createFromString($data);
     $delimiters = $csv->fetchDelimitersOccurrence([' ', '|', ',', ';'], 10);
     if (sizeof($delimiters) > 0) {
         $csv->setDelimiter(array_keys($delimiters)[0]);
     }
     return $csv;
 }
开发者ID:mayconbordin,项目名称:l5-fixtures,代码行数:13,代码来源:CsvLoader.php

示例7: spreadsheetAsCsv

 public function spreadsheetAsCsv()
 {
     $url = "https://docs.google.com/spreadsheets/d/{$this->fileId}/export?format=csv&gid={$this->gId}";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $reader = Reader::createFromString(curl_exec($ch));
     curl_close($ch);
     return $reader->fetchAssoc(0);
 }
开发者ID:dlai286,项目名称:spreadsheet,代码行数:10,代码来源:Spreadsheet.php

示例8: parse

 public function parse($content)
 {
     $reader = Reader::createFromString($content);
     $reader->setDelimiter($this->delimiter);
     $reader->setNewline($this->newline);
     $reader->setEnclosure($this->enclosure);
     $reader->setEscape($this->escapeChar);
     $reader->setFlags($this->flags);
     if ($this->hasHeader) {
         return array_slice($reader->fetchAssoc($reader->fetchOne()), 1);
     }
     return $reader->fetchAll();
 }
开发者ID:allmarkedup,项目名称:dayglo,代码行数:13,代码来源:CsvParser.php

示例9: send

 private function send()
 {
     try {
         $response = $this->client->get(null, ['body' => $this->request]);
     } catch (ClientException $e) {
         throw new FirstDataException($e->getResponse()->getBody());
     }
     $inputCsv = Reader::createFromString($response->getBody());
     $inputCsv->setDelimiter(',');
     $inputCsv->setEncodingFrom('ISO-8859-15');
     $inputCsv->setFlags(SplFileObject::DROP_NEW_LINE | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
     return $inputCsv->fetchAssoc();
 }
开发者ID:loganhenson,项目名称:firstdata,代码行数:13,代码来源:Search.php

示例10: getRows

 /**
  * Extract user rows from CSV string
  *
  * @param $csv
  * @return \Iterator
  */
 private function getRows($csv)
 {
     $reader = Reader::createFromString($csv);
     $reader->setDelimiter($this->delimiter);
     // Find column positions
     $columns = $this->findColumns($reader->fetchOne());
     return $reader->setOffset(1)->fetch(function ($row) use($columns) {
         $user = [];
         foreach ($columns as $key => $name) {
             $user[$name] = $row[$key];
         }
         return $user;
     });
 }
开发者ID:beloop,项目名称:components,代码行数:20,代码来源:ExtractUsersFromCSV.php

示例11: postUpload

 public function postUpload()
 {
     $files = $this->flyLocal()->listContents();
     foreach ($files as $file) {
         if (preg_match('/.csv$/', $file['basename'])) {
             $contents = $this->flyLocal()->readAndDelete($file['basename']);
             $csv = Reader::createFromString($contents);
             $rows = $csv->setOffset(1)->fetchAll();
             foreach ($rows as $row) {
                 $item = new Item();
                 $item->date = strtotime($row[0]);
                 $item->category = $row[1];
                 $item->title = $row[2];
                 $item->location = $row[3];
                 $item->condition = $row[4];
                 $item->amount = $row[5];
                 $item->tax_name = $row[6];
                 $item->tax_amount = $row[7];
                 $item->save();
             }
         }
     }
     return redirect('admin');
 }
开发者ID:sdavis1902,项目名称:webdev-challenge,代码行数:24,代码来源:AdminController.php

示例12: processWorkerunitData

 public function processWorkerunitData($csvresult, $preview = false)
 {
     set_time_limit(6000);
     $csvLines = explode("\n", $csvresult['content']);
     $csvLines = array_filter($csvLines, 'strlen');
     // $csvLines = array_slice($csvLines, 0, 2);
     $csv = Reader::createFromString(implode("\n", $csvLines));
     $delimiter = $csv->detectDelimiter();
     $csv->setDelimiter($delimiter);
     $headers = $csv->fetchOne();
     // dd($headers);
     foreach ($headers as $columnIndex => $columnValue) {
         if ($columnValue == "") {
             $headers[$columnIndex] = "empty_" . $columnIndex;
         }
     }
     $rowsMappedWithUnits = array();
     $batch = array();
     // dd($headers);
     // dd($csv->fetchAll());
     $workerunitCSVArray = $csv->fetchAssoc($headers);
     unset($workerunitCSVArray[0]);
     if (strpos($csvresult->title, 'relexcorrected') !== false || strpos($csvresult->title, 'reldir') !== false) {
         $result = $this->processRel($csvresult, $workerunitCSVArray, $preview);
         return $result;
     }
     // dd($workerunitCSVArray);
     $inputCSVFiles = \MongoDB\Entity::where('documentType', 'csvresult')->where('title', 'like', '%input%')->get();
     $processedInputCSVFiles = array();
     foreach ($inputCSVFiles as $inputCSVFile) {
         array_push($processedInputCSVFiles, $this->processInputData($inputCSVFile->toArray(), true));
     }
     $aggregatedProcessedInputCSVFiles = array();
     foreach ($processedInputCSVFiles as $processedInputCSVFile) {
         foreach ($processedInputCSVFile as $processedInputCSVFileMapped) {
             array_push($aggregatedProcessedInputCSVFiles, $processedInputCSVFileMapped);
         }
     }
     $mappedWorkerunitsWithUnits = array();
     $batchOfUnits = array();
     foreach ($workerunitCSVArray as $workerunitRow) {
         foreach ($aggregatedProcessedInputCSVFiles as $mappedInputRow) {
             if (strpos($csvresult->title, 'workerunit_output_cf_factorspan_merged_relex') !== false) {
                 if (stripos($workerunitRow['Sent_id'], '-')) {
                     $workerunitRowIndex = explode('-', $workerunitRow['Sent_id'])[0];
                 }
             } else {
                 $workerunitRowIndex = $workerunitRow['index'];
             }
             if ($workerunitRowIndex == $mappedInputRow['index']) {
                 $mappedWorkerunitWithUnit = $workerunitRow;
                 $mappedWorkerunitWithUnit['unit'] = $mappedInputRow['unit'];
                 array_push($batchOfUnits, $mappedInputRow['unit']['_id']);
                 array_push($mappedWorkerunitsWithUnits, $mappedWorkerunitWithUnit);
             }
         }
     }
     $batchOfUnits = array_values(array_unique($batchOfUnits));
     natsort($batchOfUnits);
     $batchOfUnits = array_values($batchOfUnits);
     if ($preview == true) {
         return $mappedWorkerunitsWithUnits;
     }
     if (stripos($csvresult->title, "factorspan") && stripos($csvresult->title, "380140")) {
         $status = $this->factorspan_308140($csvresult, $batchOfUnits, $mappedWorkerunitsWithUnits);
     } elseif (stripos($csvresult->title, "factorspan") && stripos($csvresult->title, "380640")) {
         $status = $this->factorspan_380640($csvresult, $batchOfUnits, $mappedWorkerunitsWithUnits);
     } elseif (stripos($csvresult->title, "factorspan") && stripos($csvresult->title, "382004")) {
         $status = $this->factorspan_382004($csvresult, $batchOfUnits, $mappedWorkerunitsWithUnits);
     } elseif (strpos($csvresult->title, 'annotation_output_cf_factorspan_merged_relex') !== false) {
         $status = $this->workerunit_output_cf_factorspan_merged_relex($mappedWorkerunitsWithUnits);
     } elseif (stripos($csvresult->title, "relexu") && stripos($csvresult->title, "f387177")) {
         $status = $this->relexu_f387177($csvresult, $batchOfUnits, $mappedWorkerunitsWithUnits);
     } elseif (stripos($csvresult->title, "relexu") && stripos($csvresult->title, "f387719")) {
         $status = $this->relexu_f387719($csvresult, $batchOfUnits, $mappedWorkerunitsWithUnits);
     } elseif (stripos($csvresult->title, "relexu") && stripos($csvresult->title, "f388572")) {
         $status = $this->relexu_f388572($csvresult, $batchOfUnits, $mappedWorkerunitsWithUnits);
     }
     return $status;
 }
开发者ID:harixxy,项目名称:CrowdTruth,代码行数:80,代码来源:CSVresultMapper.php

示例13: processRows

 public function processRows()
 {
     $csv = Reader::createFromString($this->data);
     $csv->setOffset(1);
     // Add filter to skip empty rows
     $csv->addFilter(function ($row) {
         return strlen(trim(implode('', $row))) > 0;
     });
     $columnMap = $this->getModelInstance()->getColumnMap();
     $columns = array_keys($columnMap);
     $csv->each(function ($row, $index) use($columns, $columnMap) {
         $this->refresh();
         if ($this->abort) {
             return false;
         }
         try {
             $row = array_combine($columns, $row);
             if (!$this->processRow($row, $columnMap, $index)) {
                 $this->error_count++;
             }
         } catch (\yii\base\Exception $e) {
             Yii::error($e->getMessage());
             $this->status_id = Import::STATUS_ERROR;
             return false;
         }
         $this->processed_rows++;
         $this->progress = $this->getPercent();
         $this->update(false, ['processed_rows', 'progress', 'status_id', 'error_count']);
         return true;
     });
 }
开发者ID:webtoolsnz,项目名称:yii2-importer,代码行数:31,代码来源:Import.php

示例14: getDocumentData

 /**
  * Load content of a document (CSV) as a data matrix.
  * 
  * @param $documentContent		Raw content of CSV file.
  * @param $delimiter			CSV field delimiter.
  * @param $separator			CSV column separator.
  * @param $ignoreHeader			Boolean flag for ignoring headers.
  * @param $nLines				Maximum number of lines to read from file (-1 to read all)
  * @return Data matrix representing the file contents.
  */
 private function getDocumentData($documentContent, $delimiter, $separator, $ignoreHeader, $nLines)
 {
     $reader = Reader::createFromString($documentContent);
     $reader->setDelimiter($separator);
     $reader->setEnclosure($delimiter);
     if ($ignoreHeader) {
         $reader->setLimit($nLines);
     } else {
         $reader->setOffset(1);
         $reader->setLimit($nLines + 1);
     }
     $dataTable = $reader->fetchAll();
     return $dataTable;
 }
开发者ID:crowdtruth,项目名称:crowdtruth,代码行数:24,代码来源:TextController.php

示例15: getColumns

 /**
  * Get table columns
  * @returns array
  */
 public function getColumns($table)
 {
     $reader = \League\Csv\Reader::createFromString(implode("\n", $this->_getCSVArray($table, true)));
     return $reader->fetchOne(0);
 }
开发者ID:tangervu,项目名称:phpaccess,代码行数:9,代码来源:PHPAccess.php


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