本文整理汇总了PHP中League\Csv\Writer::createFromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Writer::createFromString方法的具体用法?PHP Writer::createFromString怎么用?PHP Writer::createFromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Csv\Writer
的用法示例。
在下文中一共展示了Writer::createFromString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createCsv
private function createCsv($inquiryList)
{
$writer = Writer::createFromString("");
$writer->setNewline("\r\n");
foreach ($inquiryList as $inquiry) {
/** @var Inquiry $inquiry */
$writer->insertOne([$inquiry->getId(), $inquiry->getName(), $inquiry->getEmail()]);
}
return (string) $writer;
}
示例2: generate
/**
* Generates a CSV string from given array data
*
* @param array $data
*
* @throws \RuntimeException
*
* @return string
*/
public function generate(array $data)
{
$writer = Writer::createFromString('');
$writer->setDelimiter($this->delimiter);
$writer->setEnclosure($this->enclosure);
if (!is_array($data[0])) {
$data = [$data];
}
$writer->insertAll($data);
return $writer->__toString();
}
示例3: build
public function build($keyword)
{
$inquiryList = $this->inquiryRepository->findAllByKeyword($keyword);
/** @var Writer $writer */
$writer = Writer::createFromString("");
$writer->setNewline("\r\n");
foreach ($inquiryList as $inquiry) {
$writer->insertOne([$inquiry->getId(), $inquiry->getName(), $inquiry->getEmail()]);
}
return mb_convert_encoding((string) $writer, $this->encoding, 'UTF-8');
}
示例4: result
/**
* @inheritdoc
*/
public function result(AnalysisResult $result)
{
$writer = Writer::createFromString('');
$writer->insertOne(['File', 'Line', 'Tool', 'Type', 'Message']);
foreach ($result->toArray() as $fileName => $lines) {
foreach ($lines as $lineNumber => $issues) {
foreach ($issues as $issue) {
$writer->insertOne([$fileName, $lineNumber, $issue['tool'], $issue['type'], trim($issue['message'])]);
}
}
}
$csv = ltrim($writer->__toString());
$this->cli->out($csv);
}
示例5:
use League\Csv\Writer;
use League\Csv\Reader;
require '../vendor/autoload.php';
//we are creating a CSV from a raw string
$rawCsv = <<<EOF
Melodie;6;F;2011
Melody;7;F;2011
Melvil;13;M;2011
Melvin;9;M;2011
Menahem;6;M;2011
Mendel;7;M;2011
Meriem;8;F;2011
Merlin;8;M;2011
Meryam;7;F;2011
EOF;
$writer = Writer::createFromString($rawCsv);
//because we raw string delimiter is ";"
//the string delimiter MUST also be ";"
$writer->setDelimiter(';');
//we are creating a CSV from a raw string
$rawCsv2Merge = <<<EOF
Ben,7,M,2007
Benjamin,78,M,2007
Benoît,17,M,2007
Berenice,19,F,2007
Bertille,9,F,2007
Bianca,18,F,2007
Bilal,26,M,2007
Bilel,7,M,2007
EOF;
$csv2merge = Reader::createFromString($rawCsv2Merge);