ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
SimpleExcel\Parser\CSVParser Class Reference
+ Inheritance diagram for SimpleExcel\Parser\CSVParser:
+ Collaboration diagram for SimpleExcel\Parser\CSVParser:

Public Member Functions

 loadFile ($file_path)
 Load the CSV file to be parsed. More...
 
 loadString ($str)
 Load the string to be parsed. More...
 
 setDelimiter ($delimiter)
 Set delimiter that should be used to parse CSV document. More...
 
- Public Member Functions inherited from SimpleExcel\Parser\BaseParser
 __construct ($file_url=NULL)
 
 getCell ($row_num, $col_num, $val_only=true)
 Get value of the specified cell. More...
 
 getColumn ($col_num, $val_only=TRUE)
 Get data of the specified column as an array. More...
 
 getField ($val_only=TRUE)
 Get data of all cells as an array. More...
 
 getRow ($row_num, $val_only=TRUE)
 Get data of the specified row as an array. More...
 
 isCellExists ($row_num, $col_num)
 Check whether cell with specified row & column exists. More...
 
 isColumnExists ($col_num)
 Check whether a specified column exists. More...
 
 isRowExists ($row_num)
 Check whether a specified row exists. More...
 
 isFieldExists ()
 Check whether table exists. More...
 
 isFileReady ($file_path)
 Check whether file exists, valid, and readable. More...
 
 getCell ($row_num, $col_num, $val_only)
 
 getColumn ($col_num, $val_only)
 
 getRow ($row_num, $val_only)
 
 getField ($val_only)
 
 isCellExists ($row_num, $col_num)
 
 isColumnExists ($col_num)
 
 isRowExists ($row_num)
 
 isFieldExists ()
 
 isFileReady ($file_path)
 
 loadFile ($file_path)
 
 loadString ($str)
 

Protected Attributes

 $delimiter
 
 $file_extension = 'csv'
 
- Protected Attributes inherited from SimpleExcel\Parser\BaseParser
 $table_arr
 
 $file_extension = ''
 

Detailed Description

Definition at line 13 of file CSVParser.php.

Member Function Documentation

◆ loadFile()

SimpleExcel\Parser\CSVParser::loadFile (   $file_path)

Load the CSV file to be parsed.

Parameters
string$file_pathPath to CSV file

Implements SimpleExcel\Parser\IParser.

Definition at line 36 of file CSVParser.php.

36 {
37
38 if (!$this->isFileReady($file_path)) {
39 return;
40 }
41
42 $this->loadString(file_get_contents($file_path));
43 }
isFileReady($file_path)
Check whether file exists, valid, and readable.
Definition: BaseParser.php:169
loadString($str)
Load the string to be parsed.
Definition: CSVParser.php:50

References SimpleExcel\Parser\BaseParser\isFileReady(), and SimpleExcel\Parser\CSVParser\loadString().

+ Here is the call graph for this function:

◆ loadString()

SimpleExcel\Parser\CSVParser::loadString (   $str)

Load the string to be parsed.

Parameters
string$strString with CSV format

Implements SimpleExcel\Parser\IParser.

Definition at line 50 of file CSVParser.php.

50 {
51 $this->table_arr = array();
52
53 if(!isset($this->delimiter)){
54 $numofcols = NULL;
55 // assume the delimiter is semicolon
56 while(($line = str_getcsv($str, ';')) !== FALSE){
57 if($numofcols === NULL){
58 $numofcols = count($line);
59 }
60 // check the number of values in each line
61 if(count($line) === $numofcols){
62 array_push($this->table_arr, $line);
63 } else {
64 // maybe wrong delimiter
65 // empty the array back
66 $this->table_arr = array();
67 $numofcols = NULL;
68 break;
69 }
70 }
71 // if null, check whether values are separated by commas
72 if($numofcols === NULL){
73 while(($line = str_getcsv($str, ',')) !== FALSE){
74 array_push($this->table_arr, $line);
75 }
76 }
77 } else {
78 while(($line = str_getcsv($str, $this->delimiter)) !== FALSE){
79 array_push($this->table_arr, $line);
80 }
81 }
82 }

Referenced by SimpleExcel\Parser\CSVParser\loadFile().

+ Here is the caller graph for this function:

◆ setDelimiter()

SimpleExcel\Parser\CSVParser::setDelimiter (   $delimiter)

Set delimiter that should be used to parse CSV document.

Parameters
string$delimiterDelimiter character

Reimplemented in SimpleExcel\Parser\TSVParser.

Definition at line 89 of file CSVParser.php.

89 {
90 $this->delimiter = $delimiter;
91 }

References SimpleExcel\Parser\CSVParser\$delimiter.

Field Documentation

◆ $delimiter

SimpleExcel\Parser\CSVParser::$delimiter
protected

Definition at line 21 of file CSVParser.php.

Referenced by SimpleExcel\Parser\CSVParser\setDelimiter().

◆ $file_extension

SimpleExcel\Parser\CSVParser::$file_extension = 'csv'
protected

Definition at line 29 of file CSVParser.php.


The documentation for this class was generated from the following file: