TsvParser.php
Go to the documentation of this file.
00001 <?php 00002 00003 00040 class TsvParser 00041 { 00042 public $resources = array(); 00043 00045 private $fileContent = ""; 00046 00047 private $delimiter = ""; 00048 00049 function __construct($content, $delimiter) 00050 { 00051 $this->fileContent = $content; 00052 $this->delimiter = $delimiter; 00053 00054 // Parse the CSV file 00055 $this->parse(); 00056 } 00057 00058 function __destruct() { } 00059 00060 private function parse() 00061 { 00062 $resourcesLines = explode("\n", $this->fileContent); 00063 00064 $uri = ""; 00065 00066 foreach($resourcesLines as $line) 00067 { 00068 $lineValues = explode($this->delimiter, $line); 00069 00070 if($lineValues[0] != "") 00071 { 00072 $uri = $lineValues[0]; 00073 00074 if(!isset($this->resources[$uri])) 00075 { 00076 $this->resources[$uri] = array(); 00077 } 00078 } 00079 else 00080 { 00081 continue; 00082 } 00083 00084 if($lineValues[1] != "" && $lineValues[2] != "") 00085 { 00086 array_push($this->resources[$uri], array ($lineValues[1], $lineValues[2])); 00087 } 00088 } 00089 } 00090 } 00091 00092 00094 00095 ?>
