Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once "./ProgramJAO.php";
- $program = new ProgramJAO();
- $program->main();
- print_r($program->wynik);
- ?>
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of ProgramJAO
- *
- * @author student
- */
- class ProgramJAO {
- //put your code here
- public $wynik;
- public function main(){
- $zbiory = array(); //1
- $zbior = array(); //1
- $plik = fopen('dane.txt', 'r'); //3
- $znaki = array(" ", "\t", "\r", "\n");
- $noweZnaki = "";
- if(FALSE ===$plik){
- throw new Exception('Blad przy otwieraniu pliku');
- }
- while(FALSE === feof($plik)){//4
- $linia = fgets($plik, 4096);
- if(FALSE === $linia){//4.2
- break;
- }
- $linia = str_replace($znaki, $noweZnaki, $linia);//4.3
- $znak1 = substr($linia, 0, 1);
- $znakN = substr($linia, -1);
- if($znak1 !== "{" && $znakN !== "}"){//4.4
- break;
- }
- $linia = rtrim($linia, "{");//4.5
- $linia = ltrim($linia, "}");
- $zbior = explode(",", $linia);//4.6
- $zbiory[] = $zbior;//4.7
- }
- fclose($plik);//5
- $this->wynik = $zbiory;//6
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement