當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CSV::add_row方法代碼示例

本文整理匯總了PHP中CSV::add_row方法的典型用法代碼示例。如果您正苦於以下問題:PHP CSV::add_row方法的具體用法?PHP CSV::add_row怎麽用?PHP CSV::add_row使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CSV的用法示例。


在下文中一共展示了CSV::add_row方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: load

 /**
  * This function will load a CSV file.
  *
  * @access public
  * @static
  * @param array $config                             the configuration array
  * @return CSV                                      an instance of the CSV class containing
  *                                                  the contents of the file.
  *
  * @see http://www.php.net/manual/en/function.fgetcsv.php
  */
 public static function load($config = array())
 {
     $csv = new CSV($config);
     if (file_exists($csv->file_name)) {
         if (($fp = fopen($csv->file_name, 'r')) !== FALSE) {
             $eol = $csv->eol == "\r\n" ? array(13, 10) : array(ord($csv->eol));
             // 13 => cr, 10 => lf
             $buffer = '';
             while (($char = fgetc($fp)) !== FALSE) {
                 // load char by char, to replace line endings
                 if (in_array(ord($char), $eol)) {
                     $buffer .= "\r\n";
                 } else {
                     $buffer .= $char;
                 }
             }
             fclose($fp);
             $rows = explode("\r\n", $buffer);
             $enclosure = $csv->enclosure;
             $delimiter = $enclosure . $csv->delimiter . $enclosure;
             if (empty($enclosure)) {
                 $enclosure = " \t\n\r\v";
             }
             $regex = '/' . $delimiter . '/';
             foreach ($rows as $row) {
                 $row = trim($row, $enclosure);
                 //$columns = explode($delimiter, $row);
                 $columns = preg_split($regex, $row);
                 $csv->add_row($columns);
             }
         }
     }
     return $csv;
 }
開發者ID:ruslankus,項目名稱:invoice-crm,代碼行數:45,代碼來源:CSV.php

示例2: as_csv

 /**
  * This function will create an instance of the CSV class using the data contained
  * in the result set.
  *
  * @access public
  * @param array $config                             the configuration array
  * @return CSV                                      an instance of the CSV class
  */
 public function as_csv(array $config = array())
 {
     $csv = new CSV($config);
     if ($this->is_loaded()) {
         switch ($this->type) {
             case 'array':
             case 'object':
                 foreach ($this->records as $record) {
                     $csv->add_row((array) $record);
                 }
                 break;
             default:
                 if (class_exists($this->type)) {
                     if ($this->records[0] instanceof DB_ORM_Model or method_exists($this->records[0], 'as_array')) {
                         foreach ($this->records as $record) {
                             $csv->add_row($record->as_array());
                         }
                     } else {
                         if ($this->records[0] instanceof Iterator) {
                             foreach ($this->records as $record) {
                                 $row = array();
                                 foreach ($record as $column) {
                                     $row[] = $column;
                                 }
                                 $csv->add_row($row);
                             }
                         } else {
                             foreach ($this->records as $record) {
                                 $csv->add_row(get_object_vars($record));
                             }
                         }
                     }
                 }
                 break;
         }
     }
     return $csv;
 }
開發者ID:ruslankus,項目名稱:invoice-crm,代碼行數:46,代碼來源:ResultSet.php


注:本文中的CSV::add_row方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。