<?php class bullshit { public $total_engineers; public $total_drinks; public $engineer = array(); public $drink = array(); public $path; private $io; public $enable_output = true; public function __construct($p) { $this->total_engineers = 0; $this->total_drinks = 0; $this->path = $p; } public function __readfile() { $this->io = fopen($this->path, "r") or die("aaa"); flock($this->io, 2); } private function __setTotalDrinks($value) { $this->total_drinks = $value; } private function __setTotalEngineers($value) { $this->total_engineers = $value; } public function __getValueBySeperator($string, $seperator) { $string_array = explode(",", $string); return $string_array; } public function __readline($line) { $current_row = 0; for ($i = 0; !feof($this->io); $i++) { if ($current_row < $line) { if ($current_row == 0) { $element = fgetcsv($this->io, 1000, " "); $this->__setTotalEngineers($element[0]); $this->__setTotalDrinks($element[1]); } else if ($current_row > 0 && $current_row < ($this->total_drinks + 1)) { $element = fgetcsv($this->io, 1000, "\t"); array_push($this->drink, $element[1]); } else if ($current_row >= ($this->total_drinks + 1) && $current_row <= ($this->total_engineers + $this->total_drinks + 1)) { $element = fgetcsv($this->io, 1000, "\t"); array_push($this->engineer, $element[1]); } if ($this->enable_output) { echo $element[0] . " " . $element[1] . "<br/>"; } } $current_row++; } } public function __assignDrinkNameToEngineer() { foreach ($this->engineer as $Name => $value) { if (strlen($value) > 0) { echo "Engineer[" . $Name . "] = "; $drink = $this->__getValueBySeperator($value, ","); foreach ($drink as $N => $DrinkValue) { if (strlen($DrinkValue) > 0) { echo $this->drink[$DrinkValue].","; } } echo "<br/>"; } } } } $bullshit = new bullshit("test.txt"); $bullshit->enable_output = true; $bullshit->__readfile(); $bullshit->__readline(100); $bullshit->__assignDrinkNameToEngineer(); ?>