ILIAS  release_4-4 Revision
SimpleExcel\Parser\HTMLParser Class Reference
+ Inheritance diagram for SimpleExcel\Parser\HTMLParser:
+ Collaboration diagram for SimpleExcel\Parser\HTMLParser:

Public Member Functions

 loadFile ($file_path)
 Load the HTML file to be parsed. More...
 
 loadString ($str)
 Load the string to be parsed. 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...
 

Protected Attributes

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

Private Member Functions

 parseDOM ($html)
 Process the loaded file/string. More...
 

Detailed Description

Definition at line 13 of file HTMLParser.php.

Member Function Documentation

◆ loadFile()

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

Load the HTML file to be parsed.

Parameters
string$file_pathPath to HTML file

Implements SimpleExcel\Parser\IParser.

Definition at line 70 of file HTMLParser.php.

References SimpleExcel\Parser\BaseParser\isFileReady(), and SimpleExcel\Parser\HTMLParser\parseDOM().

70  {
71 
72  if (!$this->isFileReady($file_path)) {
73  return;
74  }
75 
76  $html = new \DOMDocument();
77  $html->loadHTMLFile($file_path);
78  $this->parseDOM($html);
79  }
isFileReady($file_path)
Check whether file exists, valid, and readable.
Definition: BaseParser.php:169
parseDOM($html)
Process the loaded file/string.
Definition: HTMLParser.php:28
+ Here is the call graph for this function:

◆ loadString()

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

Load the string to be parsed.

Parameters
string$strString with HTML format

Implements SimpleExcel\Parser\IParser.

Definition at line 86 of file HTMLParser.php.

References SimpleExcel\Parser\HTMLParser\parseDOM().

86  {
87  $html = new \DOMDocument();
88  $html->loadHTML($str);
89  $this->parseDOM($html);
90  }
parseDOM($html)
Process the loaded file/string.
Definition: HTMLParser.php:28
+ Here is the call graph for this function:

◆ parseDOM()

SimpleExcel\Parser\HTMLParser::parseDOM (   $html)
private

Process the loaded file/string.

Parameters
DOMDocument$htmlDOMDocument object of HTML

Definition at line 28 of file HTMLParser.php.

References $row.

Referenced by SimpleExcel\Parser\HTMLParser\loadFile(), and SimpleExcel\Parser\HTMLParser\loadString().

28  {
29  $tables = $html->getElementsByTagName('table');
30  $field = array();
31  foreach ($tables as $table) {
32  $table_child = $table->childNodes;
33  foreach ($table_child as $twrap) {
34  if($twrap->nodeType === XML_ELEMENT_NODE) {
35  if ($twrap->nodeName === "thead" || $twrap->nodeName === "tbody") {
36  $twrap_child = $twrap->childNodes;
37  foreach ($twrap_child as $tr) {
38  if($tr->nodeType === XML_ELEMENT_NODE && $tr->nodeName === "tr") {
39  $row = array();
40  $tr_child = $tr->childNodes;
41  foreach ($tr_child as $td) {
42  if ($td->nodeType === XML_ELEMENT_NODE && ($td->nodeName === "th" || $td->nodeName === "td")) {
43  array_push($row, $td->nodeValue);
44  }
45  }
46  array_push($field, $row);
47  }
48  }
49  } else if ($twrap->nodeName === "tr") {
50  $row = array();
51  $twrap_child = $twrap->childNodes;
52  foreach ($twrap_child as $td) {
53  if ($td->nodeType === XML_ELEMENT_NODE && ($td->nodeName === "th" || $td->nodeName === "td")) {
54  array_push($row, $td->nodeValue);
55  }
56  }
57  array_push($field, $row);
58  }
59  }
60  }
61  }
62  $this->table_arr = $field;
63  }
+ Here is the caller graph for this function:

Field Documentation

◆ $file_extension

SimpleExcel\Parser\HTMLParser::$file_extension = 'html'
protected

Definition at line 21 of file HTMLParser.php.


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