本文整理汇总了PHP中CSV类的典型用法代码示例。如果您正苦于以下问题:PHP CSV类的具体用法?PHP CSV怎么用?PHP CSV使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CSV类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHugeNumberOfColumns
public function testHugeNumberOfColumns()
{
$obj = new CSV();
$data = $obj->with(__DIR__ . '/read_hugenumberofcolumns.csv')->toArray();
$arr = array(array_fill(0, 2000, 'row'));
$this->assertEquals($data, $arr);
}
示例2: testCustomDelimiter
public function testCustomDelimiter()
{
$csv = new CSV($this->rows, $this->headers, '|');
$output = $csv->render();
$expected = "name|age\nandrew|25\nbob|37\n";
$this->assertEquals($expected, $output);
}
示例3: exportOperation
/**
* @name exportOperation($pParam)
* @desc Donne les opérations sur le compte du zeybu
*/
public function exportOperation($pParam)
{
$lVr = CompteAssociationValid::validRecherche($pParam);
if ($lVr->getValid()) {
$lDateDebut = NULL;
if (!empty($pParam['dateDebut'])) {
$lDateDebut = $pParam['dateDebut'];
}
$lDateFin = NULL;
if (!empty($pParam['dateFin'])) {
$lDateFin = $pParam['dateFin'];
}
$lCSV = new CSV();
$lCSV->setNom('CompteAssociation.csv');
// Le Nom
// L'entete
$lEntete = array("Date", "Compte", "Libelle", "Paiement", "N°", "Debit", "", "Credit", "");
$lCSV->setEntete($lEntete);
// Les données
$lOperationService = new OperationService();
$lOperations = $lOperationService->rechercheOperationAssociation($lDateDebut, $lDateFin);
$lContenuTableau = array();
foreach ($lOperations as $lOperation) {
$lDate = StringUtils::extractDate($lOperation->getOpeDate());
$lPaiement = '';
if (!is_null($lOperation->getTppType())) {
$lPaiement = $lOperation->getTppType();
}
$lCheque = '';
if (!is_null($lOperation->getNumeroCheque())) {
$lCheque = $lOperation->getNumeroCheque();
}
$lDebit = '';
$lCredit = '';
if ($lOperation->getOpeMontant() < 0) {
$lDebit = $lOperation->getOpeMontant() * -1;
} else {
$lCredit = $lOperation->getOpeMontant();
}
$lLignecontenu = array($lDate, $lOperation->getCptLabel(), $lOperation->getOpeLibelle(), $lPaiement, $lCheque, $lDebit, SIGLE_MONETAIRE, $lCredit, SIGLE_MONETAIRE);
array_push($lContenuTableau, $lLignecontenu);
}
$lCSV->setData($lContenuTableau);
// Export en CSV
$lCSV->output();
} else {
return $lVr;
}
}
示例4: getListePaiementExport
/**
* @name getListePaiementExport($pParam)
* @return InfoMarcheVR
* @desc Retourne la liste des adhérents qui ont réservé sur cette commande et les infos sur la commande.
*/
public function getListePaiementExport($pParam)
{
$lVr = MarcheValid::validGetMarche($pParam);
if ($lVr->getValid()) {
$lIdMarche = $pParam["id"];
$lTypePaiement = $pParam["type"];
$lCSV = new CSV();
$lCSV->setNom('Caisse.csv');
// Le Nom
// L'entete
$lEntete = array("Date", "N°", "Compte", "Nom", "Prénom", "Montant", "");
$lOperationService = new OperationService();
if ($lTypePaiement == 1) {
$lOperations = $lOperationService->getListeEspeceCaisse($lIdMarche);
} else {
array_push($lEntete, "N°");
$lOperations = $lOperationService->getListeChequeCaisse($lIdMarche);
}
$lCSV->setEntete($lEntete);
// Les données
$lContenuTableau = array();
foreach ($lOperations as $lOperation) {
if (!is_null($lOperation->getCptLabel())) {
$lDate = StringUtils::extractDate($lOperation->getOpeDate());
if (is_null($lOperation->getAdhNumero())) {
$lAdhNumero = '';
$lAdhNom = '';
$lAdhPrenom = '';
} else {
$lAdhNumero = $lOperation->getAdhNumero();
$lAdhNom = $lOperation->getAdhNom();
$lAdhPrenom = $lOperation->getAdhPrenom();
}
$lLignecontenu = array($lDate, $lAdhNumero, $lOperation->getCptLabel(), $lAdhNom, $lAdhPrenom, $lOperation->getOpeMontant(), SIGLE_MONETAIRE);
if ($lTypePaiement == 2) {
$lChampComplementaire = $lOperation->getOpeTypePaiementChampComplementaire();
array_push($lLignecontenu, $lChampComplementaire[3]->getValeur());
}
array_push($lContenuTableau, $lLignecontenu);
}
}
$lCSV->setData($lContenuTableau);
// Export en CSV
$lCSV->output();
} else {
return $lVr;
}
}
示例5: OnLoadPageData
function OnLoadPageData()
{
# Require an API key to include personal contact details to avoid spam bots picking them up
$api_keys = $this->GetSettings()->GetApiKeys();
$valid_key = false;
if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
$valid_key = true;
}
$data = array();
$data[] = array("Match id", "Title", "Start time", "Latitude", "Longitude", "Website", "Description");
require_once 'stoolball/match-manager.class.php';
require_once "search/match-search-adapter.class.php";
$match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection());
$match_manager->FilterByDateStart(gmdate("U"));
$match_manager->ReadByMatchId();
while ($match_manager->MoveNext()) {
$match = $match_manager->GetItem();
$adapter = new MatchSearchAdapter($match);
/* @var $match Match */
# Add this match to the data array
$data[] = array($match->GetId(), $match->GetTitle(), $match->GetStartTime(), $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLatitude() : "", $match->GetGround() instanceof Ground ? $match->GetGround()->GetAddress()->GetLongitude() : "", "https://" . $this->GetSettings()->GetDomain() . $match->GetNavigateUrl(), $adapter->GetSearchDescription());
}
unset($match_manager);
require_once "data/csv.class.php";
CSV::PublishData($data);
# Test code only. Comment out CSV publish line above to enable display as a table.
require_once "xhtml/tables/xhtml-table.class.php";
$table = new XhtmlTable();
$table->BindArray($data, false, false);
echo $table;
}
示例6: generate
public function generate()
{
$reportManager = new ReportManager(Input::all());
$report = $reportManager->generate();
$dateTime = new DateTime('NOw');
return CSV::fromArray($report)->setHeaderRowExists(false)->render('Reporte_' . Input::get('report', '') . '_' . $dateTime->getTimestamp() . '.csv');
}
示例7: read
static function read()
{
$items = array();
while (($data = CSV::read_line()) !== FALSE) {
$items[] = $data;
}
return $items;
}
示例8: testPutCreatesFile
public function testPutCreatesFile()
{
$obj = new CSV();
$arr = array(array('name' => 'name1', 'address' => 'address1'), array('name' => 'name2', 'address' => 'address2'));
$obj->with($arr)->put('tests' . DIRECTORY_SEPARATOR . 'putTest.csv');
$this->assertFileExists('tests' . DIRECTORY_SEPARATOR . 'putTest.csv');
unlink('tests' . DIRECTORY_SEPARATOR . 'putTest.csv');
}
示例9: saveToCSV
function saveToCSV($extend_to_resources = true, $filename = null)
{
if (!$filename) {
$csv = new CSV("csv/datasets-" . date("YmdHis") . "-" . max(0, $extend_to_resources) . ".csv");
} else {
$csv = new CSV($filename);
}
if ($extend_to_resources) {
$csv->addArrayHeader(array("Thema", "Categorie", "Naam", "Titel", "Beschrijving", "Tags", "Eigenaar", "Eigenaar e-mail", "Contactpersoon", "Contact e-mail", "Webadres", "Vrijgegeven", "Aangepast", "Tijd vanaf", "Tijd tot", "Tijd detailniveau", "Updatefrequentie", "Licentie", "Dataset url", "Dataset beschrijving", "Bestandsformaat"));
} else {
$csv->addArrayHeader(array("Thema", "Categorie", "Naam", "Titel", "Beschrijving", "Tags", "Eigenaar", "Eigenaar e-mail", "Contactpersoon", "Contact e-mail", "Webadres", "Vrijgegeven", "Aangepast", "Tijd vanaf", "Tijd tot", "Tijd detailniveau", "Updatefrequentie", "Licentie", "Directe url", "Aantal datasets", "Datasets"));
}
foreach ($this->datasets as $name => $dataset) {
if ($extend_to_resources) {
foreach ($dataset->res_description as $key => $description) {
$thema = $this->themas[$dataset->groups[0]];
$categorie = $this->categorien[$dataset->groups[0]];
$item = array($thema, $categorie, $dataset->name, $dataset->title, $dataset->notes, implode(" ", $dataset->tags), $dataset->author, $dataset->author_email, $dataset->extras->contact_name, $dataset->extras->contact_email, $dataset->extras->website, $dataset->extras->publication_date, $dataset->metadata_modified, $dataset->extras->time_period_from, $dataset->extras->time_period_to, $dataset->extras->time_period_detail_level, $dataset->extras->update_frequency, $dataset->license_id, $dataset->res_url[$key], $description, $dataset->res_format[$key]);
$csv->addArray($item);
}
} else {
//Only datasets
$thema = $this->themas[$dataset->groups[0]];
$categorie = $this->categorien[$dataset->groups[0]];
$url = DATA_URL . "?dataset=" . $dataset->name;
$count = 0;
$sets = "";
$splitter = "";
foreach ($dataset->res_description as $key => $description) {
$count++;
$sets .= $splitter . $description;
$splitter = ", ";
}
$item = array($thema, $categorie, $dataset->name, $dataset->title, $dataset->notes, implode(" ", $dataset->tags), $dataset->author, $dataset->author_email, $dataset->extras->contact_name, $dataset->extras->contact_email, $dataset->extras->website, $dataset->extras->publication_date, $dataset->metadata_modified, $dataset->extras->time_period_from, $dataset->extras->time_period_to, $dataset->extras->time_period_detail_level, $dataset->extras->update_frequency, $dataset->license_id, $url, $count, $sets);
$csv->addArray($item);
}
}
$csv->write();
}
示例10: OnLoadPageData
function OnLoadPageData()
{
# Require an API key to include personal contact details to avoid spam bots picking them up
$api_keys = $this->GetSettings()->GetApiKeys();
$valid_key = false;
if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
$valid_key = true;
}
$data = array();
$data[] = array("Club/ facility name", "Address 1", "Address 2", "Address 3", "Address 4", "Address 5", "City", "Postcode", "Country", "Tel", "Email", "Website", "Activities", "Opening times");
require_once 'stoolball/team-manager.class.php';
$team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
$team_manager->FilterByActive(true);
$team_manager->FilterByTeamType(array(Team::REGULAR));
$team_manager->ReadById();
while ($team_manager->MoveNext()) {
/* @var $team Team */
$team = $team_manager->GetItem();
# NHS choices can only import records with a postcode
if (!$team->GetGround()->GetAddress()->GetPostcode()) {
continue;
}
$address = array();
if ($team->GetGround()->GetAddress()->GetSaon()) {
$address[] = $team->GetGround()->GetAddress()->GetSaon();
}
if ($team->GetGround()->GetAddress()->GetPaon()) {
$address[] = $team->GetGround()->GetAddress()->GetPaon();
}
if ($team->GetGround()->GetAddress()->GetStreetDescriptor()) {
$address[] = $team->GetGround()->GetAddress()->GetStreetDescriptor();
}
if ($team->GetGround()->GetAddress()->GetLocality()) {
$address[] = $team->GetGround()->GetAddress()->GetLocality();
}
if ($team->GetGround()->GetAddress()->GetAdministrativeArea()) {
$address[] = $team->GetGround()->GetAddress()->GetAdministrativeArea();
}
$data[] = array($team->GetName() . " Stoolball Club", isset($address[0]) ? $address[0] : "", isset($address[1]) ? $address[1] : "", isset($address[2]) ? $address[2] : "", isset($address[3]) ? $address[3] : "", isset($address[4]) ? $address[4] : "", $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), "stoolball", preg_replace('/\\[[^]]+\\]/', "", $team->GetPlayingTimes()));
}
unset($team_manager);
require_once "data/csv.class.php";
CSV::PublishData($data);
# Test code only. Comment out CSV publish line above to enable display as a table.
require_once "xhtml/tables/xhtml-table.class.php";
$table = new XhtmlTable();
$table->BindArray($data, false, false);
echo $table;
}
示例11: getViewAllMember
/**
* This function responses to
* the get request of /admin/member
* and show all member as list
*/
public function getViewAllMember($msg = null)
{
if (!empty($msg) && $msg == 1) {
return View::make('adminArea.member.view')->with('members', Member::orderBy('id', 'desc')->get())->with('success', 'Member has been deleted successfully');
}
if (!empty($msg) && $msg == 'csv-for-mailchimp') {
$members = Member::select('first_name', 'last_name', 'email')->get()->toArray();
return CSV::fromArray($members)->render('Members CSV for MailChimp.csv');
}
if (!empty($msg) && $msg == 'csv-for-sms-sender') {
$members = Member::select('mobile_no')->get()->toArray();
return CSV::fromArray($members)->render('Members CSV for SMS Sender.csv');
}
return View::make('adminArea.member.view')->with('members', Member::orderBy('id', 'desc')->get());
}
示例12: OnLoadPageData
function OnLoadPageData()
{
# Require an API key to include personal contact details to avoid spam bots picking them up
$api_keys = $this->GetSettings()->GetApiKeys();
$valid_key = false;
if (isset($_GET['key']) and in_array($_GET['key'], $api_keys)) {
$valid_key = true;
}
$data = array();
$data[] = array("Team id", "Team name", "Player type", "Home ground name", "Street name", "Locality", "Town", "Administrative area", "Postcode", "Country", "Latitude", "Longitude", "Contact phone", "Contact email", "Website", "Description");
require_once 'stoolball/team-manager.class.php';
$team_manager = new TeamManager($this->GetSettings(), $this->GetDataConnection());
$team_manager->FilterByActive(true);
$team_manager->FilterByTeamType(array(Team::REGULAR));
$team_manager->ReadById();
while ($team_manager->MoveNext()) {
$team = $team_manager->GetItem();
/* @var $team Team */
# Spogo can only import records with contact details
if (!$team->GetContactPhone() and !$team->GetContactEmail()) {
continue;
}
# Combine free text fields into a description field
$description = $team->GetIntro();
if ($description) {
$description .= "\n\n";
}
if ($team->GetPlayingTimes()) {
$description .= $team->GetPlayingTimes() . "\n\n";
}
if ($team->GetCost()) {
$description .= $team->GetCost();
}
# Add this team to the data array
$data[] = array($team->GetId(), $team->GetName() . " Stoolball Club", PlayerType::Text($team->GetPlayerType()), $team->GetGround()->GetAddress()->GetPaon(), $team->GetGround()->GetAddress()->GetStreetDescriptor(), $team->GetGround()->GetAddress()->GetLocality(), $team->GetGround()->GetAddress()->GetTown(), $team->GetGround()->GetAddress()->GetAdministrativeArea(), $team->GetGround()->GetAddress()->GetPostcode(), "England", $team->GetGround()->GetAddress()->GetLatitude(), $team->GetGround()->GetAddress()->GetLongitude(), $valid_key ? $team->GetContactPhone() : "", $valid_key ? $team->GetContactEmail() : "", $team->GetWebsiteUrl() ? $team->GetWebsiteUrl() : "https://" . $this->GetSettings()->GetDomain() . $team->GetNavigateUrl(), trim(html_entity_decode(strip_tags($description), ENT_QUOTES)));
}
unset($team_manager);
require_once "data/csv.class.php";
CSV::PublishData($data);
# Test code only. Comment out CSV publish line above to enable display as a table.
require_once "xhtml/tables/xhtml-table.class.php";
$table = new XhtmlTable();
$table->BindArray($data, false, false);
echo $table;
}
示例13: load_data
/**
This functions loads the data related to each page or layout
for a page we load all files in the related directory
for a layout we check the "datas-sources" attribute of our layout_file.json and load them
In your real world application you can load data only when it is needed according to each page inside controllers
*/
private function load_data($data_dir)
{
$data_files = array();
$format = "/([0-9a-z\\-_]+)\\.(json|csv)\$/i";
//see if there's a folder for partial data relating to this page or layout
//if so iterate all json/csv files and load the data
$partial_data_folder = "{$data_dir}/{$this->type}s/partials/{$this->name}";
$stats = null;
if (is_dir($partial_data_folder)) {
$files = scandir($partial_data_folder);
foreach ($files as $name) {
if ($name == '.' or $name == '..') {
continue;
}
if (!preg_match($format, $name, $filename)) {
continue;
}
$data_files[$filename[1]] = "{$partial_data_folder}/{$name}";
}
}
foreach ($data_files as $var_name => $var_value) {
$new_data = '';
if (preg_match("/\\.json\$/i", $data_files[$var_name])) {
$new_data = json_decode(file_get_contents($data_files[$var_name]), TRUE);
} else {
if (preg_match("/\\.csv\$/i", $data_files[$var_name])) {
//load csv data into an array
$new_data = CSV::to_array($data_files[$var_name]);
foreach ($new_data as &$data) {
if (isset($data['status'])) {
$data[$data['status']] = true;
}
}
}
}
$this->vars[str_replace('.', '_', $var_name)] = $new_data;
//here we replace '.' with '_' in variable names, so template compiler can recognize it as a variable not an object
//for example change sidebar.navList to sidebar_navList , because sidebar is not an object
}
return true;
}
示例14: foreach
$result[0] = $r['rows'];
$r = $c->clasificacionFinal($rondas, $mangas, 3);
$result[3] = $r['rows'];
} else {
$r = $c->clasificacionFinal($rondas, $mangas, 6);
$result[6] = $r['rows'];
$r = $c->clasificacionFinal($rondas, $mangas, 7);
$result[7] = $r['rows'];
}
break;
case 2:
// recorrido conjunto large+medium+small
if ($heights == 3) {
$r = $c->clasificacionFinal($rondas, $mangas, 4);
$result[4] = $r['rows'];
} else {
$r = $c->clasificacionFinal($rondas, $mangas, 8);
$result[8] = $r['rows'];
}
break;
}
$first = true;
foreach ($result as $res) {
$csv = new CSV($prueba, $jornada, $mangas, $res);
echo $csv->composeTable($first);
$first = false;
}
} catch (Exception $e) {
do_log($e->getMessage());
die($e->getMessage());
}
示例15: convert
public function convert($filename, $format = self::STANDARD)
{
if ($this->mode != self::READ) {
return;
}
if ($format == self::AUTO) {
$format = self::STANDARD;
}
$csv = CSV::create($filename, CSV::EXCEL);
$this->each(function ($row) use($csv) {
$csv->write($row);
});
return $csv;
}