• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP CSV类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中CSV的典型用法代码示例。如果您正苦于以下问题:PHP CSV类的具体用法?PHP CSV怎么用?PHP CSV使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CSV类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
 }
开发者ID:4lb0,项目名称:csv,代码行数:7,代码来源:CSVTest.php


示例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);
 }
开发者ID:awellis13,项目名称:lib-array2csv,代码行数:7,代码来源:CSVTest.php


示例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;
     }
 }
开发者ID:google-code-backups,项目名称:zeybux,代码行数:53,代码来源:CompteAssociationControleur.php


示例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;
     }
 }
开发者ID:google-code-backups,项目名称:zeybux,代码行数:53,代码来源:PaiementCaisseControleur.php


示例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;
 }
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:31,代码来源:onlysport.php


示例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');
 }
开发者ID:flgx,项目名称:htdocs,代码行数:7,代码来源:ReportController.php


示例7: read

 static function read()
 {
     $items = array();
     while (($data = CSV::read_line()) !== FALSE) {
         $items[] = $data;
     }
     return $items;
 }
开发者ID:hubgit,项目名称:libapi,代码行数:8,代码来源:CSV.php


示例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');
 }
开发者ID:neondigital,项目名称:csv,代码行数:8,代码来源:CSVTest.php


示例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();
 }
开发者ID:AmsterdamData,项目名称:CKAN,代码行数:39,代码来源:ckan.php


示例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;
 }
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:49,代码来源:promoting-activity.php


示例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());
 }
开发者ID:madiarsa,项目名称:DVD-Rental,代码行数:20,代码来源:MemberController.php


示例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;
 }
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:45,代码来源:spogo.php


示例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;
 }
开发者ID:12liuxiangyu12,项目名称:bitles,代码行数:47,代码来源:Page.php


示例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());
}
开发者ID:nedy13,项目名称:AgilityContest,代码行数:31,代码来源:print_etiquetas_csv.php


示例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;
 }
开发者ID:caffeina-core,项目名称:core,代码行数:14,代码来源:CSV.php


示例16: __construct

<?php

class CSV
{
    //private $_csv_file = null;
    public $_csv_file = null;
    public function __construct($csv_file)
    {
        if (file_exists($csv_file)) {
            $this->_csv_file = $csv_file;
        } else {
            throw new Exception("Файл \"{$csv_file}\" не найден");
        }
    }
    public function getCSV()
    {
        $handle = fopen($this->_csv_file, "r");
        $array_line_full = array();
        while (($line = fgetcsv($handle, 0, ";")) !== FALSE) {
            $array_line_full[] = $line;
        }
        fclose($handle);
        return $array_line_full;
    }
}
///
$csv = new CSV("file.csv");
$get_csv = $csv->getCSV();
foreach ($get_csv as $value) {
    echo $value[5];
}
开发者ID:project-hh,项目名称:php,代码行数:31,代码来源:excel+CSV.php


示例17: validate_all_variables

        <script type="text/javascript" language="javascript">
	
	
	
        </script>

    </head>

    <body>

        <h1>TCAT :: Export URLs</h1>

        <?php 
validate_all_variables();
$filename = get_filename_for_export('urlsExport');
$csv = new CSV($filename, $outputformat);
$csv->writeheader(array('tweet_id', 'url', 'url_expanded', 'url_followed'));
$sql = "SELECT t.id as id, u.url as url, u.url_expanded as url_expanded, u.url_followed as url_followed FROM " . $esc['mysql']['dataset'] . "_tweets t, " . $esc['mysql']['dataset'] . "_urls u ";
$sql .= sqlSubset();
$sql .= " AND u.tweet_id = t.id ORDER BY id";
$sqlresults = mysql_unbuffered_query($sql);
$out = "";
if ($sqlresults) {
    while ($data = mysql_fetch_assoc($sqlresults)) {
        $csv->newrow();
        $csv->addfield($data['id'], 'integer');
        $csv->addfield($data['url'], 'string');
        if (isset($data['url_followed']) && strlen($data['url_followed']) > 1) {
            $csv->addfield($data['url'], 'string');
        } else {
            $csv->addfield('', 'string');
开发者ID:01123578,项目名称:dmi-tcat,代码行数:31,代码来源:mod.export_urls.php


示例18: execute

 public function execute(array &$param_pool = null)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     // When DS is called out of the Frontend context, this will enable
     // {$root} and {$workspace} parameters to be evaluated
     if (empty($this->_env)) {
         $this->_env['env']['pool'] = array('root' => URL, 'workspace' => WORKSPACE);
     }
     try {
         require_once TOOLKIT . '/class.gateway.php';
         require_once TOOLKIT . '/class.xsltprocess.php';
         require_once CORE . '/class.cacheable.php';
         $this->dsParamURL = $this->parseParamURL($this->dsParamURL);
         if (isset($this->dsParamXPATH)) {
             $this->dsParamXPATH = $this->__processParametersInString(stripslashes($this->dsParamXPATH), $this->_env);
         }
         // Builds a Default Stylesheet to transform the resulting XML with
         $stylesheet = new XMLElement('xsl:stylesheet');
         $stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform'));
         $output = new XMLElement('xsl:output');
         $output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes'));
         $stylesheet->appendChild($output);
         $template = new XMLElement('xsl:template');
         $template->setAttribute('match', '/');
         $instruction = new XMLElement('xsl:copy-of');
         // Namespaces
         if (isset($this->dsParamNAMESPACES) && is_array($this->dsParamNAMESPACES)) {
             foreach ($this->dsParamNAMESPACES as $name => $uri) {
                 $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : null), $uri);
             }
         }
         // XPath
         $instruction->setAttribute('select', $this->dsParamXPATH);
         $template->appendChild($instruction);
         $stylesheet->appendChild($template);
         $stylesheet->setIncludeHeader(true);
         $xsl = $stylesheet->generate(true);
         // Check for an existing Cache for this Datasource
         $cache_id = self::buildCacheID($this);
         $cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
         $cachedData = $cache->check($cache_id);
         $writeToCache = null;
         $isCacheValid = true;
         $creation = DateTimeObj::get('c');
         // Execute if the cache doesn't exist, or if it is old.
         if (!is_array($cachedData) || empty($cachedData) || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) {
             if (Mutex::acquire($cache_id, $this->dsParamTIMEOUT, TMP)) {
                 $ch = new Gateway();
                 $ch->init($this->dsParamURL);
                 $ch->setopt('TIMEOUT', $this->dsParamTIMEOUT);
                 // Set the approtiate Accept: headers depending on the format of the URL.
                 if ($this->dsParamFORMAT == 'xml') {
                     $ch->setopt('HTTPHEADER', array('Accept: text/xml, */*'));
                 } elseif ($this->dsParamFORMAT == 'json') {
                     $ch->setopt('HTTPHEADER', array('Accept: application/json, */*'));
                 } elseif ($this->dsParamFORMAT == 'csv') {
                     $ch->setopt('HTTPHEADER', array('Accept: text/csv, */*'));
                 }
                 self::prepareGateway($ch);
                 $data = $ch->exec();
                 $info = $ch->getInfoLast();
                 Mutex::release($cache_id, TMP);
                 $data = trim($data);
                 $writeToCache = true;
                 // Handle any response that is not a 200, or the content type does not include XML, JSON, plain or text
                 if ((int) $info['http_code'] != 200 || !preg_match('/(xml|json|csv|plain|text)/i', $info['content_type'])) {
                     $writeToCache = false;
                     $result->setAttribute('valid', 'false');
                     // 28 is CURLE_OPERATION_TIMEOUTED
                     if ($info['curl_error'] == 28) {
                         $result->appendChild(new XMLElement('error', sprintf('Request timed out. %d second limit reached.', $timeout)));
                     } else {
                         $result->appendChild(new XMLElement('error', sprintf('Status code %d was returned. Content-type: %s', $info['http_code'], $info['content_type'])));
                     }
                     return $result;
                 } else {
                     if (strlen($data) > 0) {
                         // Handle where there is `$data`
                         // If it's JSON, convert it to XML
                         if ($this->dsParamFORMAT == 'json') {
                             try {
                                 require_once TOOLKIT . '/class.json.php';
                                 $data = JSON::convertToXML($data);
                             } catch (Exception $ex) {
                                 $writeToCache = false;
                                 $errors = array(array('message' => $ex->getMessage()));
                             }
                         } elseif ($this->dsParamFORMAT == 'csv') {
                             try {
                                 require_once EXTENSIONS . '/remote_datasource/lib/class.csv.php';
                                 $data = CSV::convertToXML($data);
                             } catch (Exception $ex) {
                                 $writeToCache = false;
                                 $errors = array(array('message' => $ex->getMessage()));
                             }
                         } elseif ($this->dsParamFORMAT == 'txt') {
                             $txtElement = new XMLElement('entry');
                             $txtElement->setValue(General::wrapInCDATA($data));
                             $data = $txtElement->generate();
                             $txtElement = null;
//.........这里部分代码省略.........
开发者ID:beaubbe,项目名称:remote_datasource,代码行数:101,代码来源:datasource.remote.php


示例19: validate_all_variables

        <h1>TCAT :: Export Tweets language</h1>

        <?php 
validate_all_variables();
/* @todo, use same export possibilities as mod.export_tweets.php */
$header = "id,time,created_at,from_user_name,from_user_lang,text,source,location,lat,lng,from_user_tweetcount,from_user_followercount,from_user_friendcount,from_user_realname,to_user_name,in_reply_to_status_id,quoted_status_id,from_user_listed,from_user_utcoffset,from_user_timezone,from_user_description,from_user_url,from_user_verified,filter_leveli,cld_name,cld_code,cld_reliable,cld_bytes,cld_percent";
if (isset($_GET['includeUrls']) && $_GET['includeUrls'] == 1) {
    $header .= ",urls,urls_expanded,urls_followed,domains";
}
$header .= "\n";
$langset = $esc['mysql']['dataset'] . '_lang';
$sql = "SELECT * FROM " . $esc['mysql']['dataset'] . "_tweets t inner join {$langset} l on t.id = l.tweet_id ";
$sql .= sqlSubset();
$sqlresults = mysql_query($sql);
$filename = get_filename_for_export("fullExportLang");
$csv = new CSV($filename, $outputformat);
$csv->writeheader(explode(',', $header));
if ($sqlresults) {
    while ($data = mysql_fetch_assoc($sqlresults)) {
        $csv->newrow();
        if (preg_match("/_urls/", $sql)) {
            $id = $data['tweet_id'];
        } else {
            $id = $data['id'];
        }
        $csv->addfield($id);
        $csv->addfield(strtotime($data["created_at"]));
        $fields = array('created_at', 'from_user_name', 'from_user_lang', 'text', 'source', 'location', 'geo_lat', 'geo_lng', 'from_user_tweetcount', 'from_user_followercount', 'from_user_friendcount', 'from_user_realname', 'to_user_name', 'in_reply_to_status_id', 'quoted_status_id', 'from_user_listed', 'from_user_utcoffset', 'from_user_timezone', 'from_user_description', 'from_user_url', 'from_user_verified', 'filter_level');
        foreach ($fields as $f) {
            $csv->addfield(isset($data[$f]) ? $data[$f] : '');
        }
开发者ID:petethegreek,项目名称:dmi-tcat,代码行数:31,代码来源:mod.export_tweets_lang.php


示例20: json_encode

    echo json_encode($editdata);
    exit;
} elseif ($_GET['page'] === 'csv') {
    require_once FS_PHP . '/csv.php';
    if (!isset($_GET['status'])) {
        $_GET["status"] = 0;
    }
    $data = $equip->listItems($SESSION->department, $_GET["status"]);
    if (sizeof($data)) {
        $output = new CSV($data);
        $output->generate();
    }
} elseif ($_GET['page'] === 'export-selected') {
    require_once FS_PHP . '/csv.php';
    $data = $equip->listItemscsv(explode(',', $_GET['ids']));
    $output = new CSV($data);
    $output->generate();
} else {
    require_once FS_PHP . '/error.php';
}
//============================================================================================
// View
//============================================================================================
$actions = array('add', 'edit', 'csv', 'export-selected', 'fetch');
if (isset($render) && $render) {
    $thisPage = "Keys";
    if (isset($l10nFile) && file_exists($l10nFile)) {
        require $l10nFile;
    }
    require FS_PHP . '/header.php';
    require FS_PHP . '/nav.php';
开发者ID:hughnguy,项目名称:php,代码行数:31,代码来源:key.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP CSaleBasket类代码示例发布时间:2022-05-20
下一篇:
PHP CSSMin类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap