本文整理汇总了PHP中Writer::writeRow方法的典型用法代码示例。如果您正苦于以下问题:PHP Writer::writeRow方法的具体用法?PHP Writer::writeRow怎么用?PHP Writer::writeRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Writer
的用法示例。
在下文中一共展示了Writer::writeRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dirname
<?php
namespace EasyCSV;
require_once dirname(dirname(__DIR__)) . '/inc/common.php';
foreach (glob(CKANMNGR_DATA_DIR . '/organizations.json') as $json_file) {
$json = json_decode(file_get_contents($json_file), true);
// decode as assoc array
$basename = str_replace('.json', '', basename($json_file));
$writer = new Writer(CKANMNGR_DATA_DIR . '/' . $basename . '.csv');
// $writer->writeRow([
// 'from',
// 'to'
// ]);
foreach ($json['result'] as $organization) {
$writer->writeRow([$organization['name']]);
}
}
// show running time on finish
timer();
示例2: dirname
<?php
namespace EasyCSV;
require_once dirname(dirname(__DIR__)) . '/inc/common.php';
foreach (glob(CKANMNGR_DATA_DIR . '/de*.json') as $json_file) {
$dataset_names = json_decode(file_get_contents($json_file), true);
// decode as assoc array
$basename = str_replace('.json', '', basename($json_file));
$writer = new Writer(CKANMNGR_DATA_DIR . '/' . $basename . '.csv');
$writer->writeRow(['from', 'to']);
foreach ($dataset_names['name'] as $name => $count) {
$newName = preg_replace("/^deleted-/", '', $name);
$writer->writeRow([$name, $newName]);
}
}
// show running time on finish
timer();
示例3: Reader
// fix wrong END-OF-LINE
file_put_contents($csv_file, preg_replace('/[\\r\\n]+/', "\n", file_get_contents($csv_file)));
$csv_source = new Reader($csv_file, 'r+', false);
$csv_destination = new Writer($results_dir . '/' . $basename . '_long.csv');
$i = 0;
while (true) {
if (!($i++ % 50)) {
echo $i . PHP_EOL;
}
$row = $csv_source->getRow();
if (!$row) {
break;
}
// skip headers
if (in_array(trim(strtolower($row[0])), ['socrata code', 'from'])) {
$csv_destination->writeRow($row);
continue;
}
$socrata_id = $row[0];
$ckan_url = $row[1];
// writing short redirect
$socrata_short_url = 'https://explore.data.gov/d/' . $socrata_id;
$csv_destination->writeRow([$socrata_short_url, $ckan_url]);
$socrata_long_url = get_long_socrata_url($curl_ch, $socrata_short_url);
if (!$socrata_long_url) {
echo 'No result: ' . $socrata_short_url . PHP_EOL;
}
$csv_destination->writeRow([$socrata_long_url, $ckan_url]);
}
}
/**