Advertisement
Guest User

Untitled

a guest
May 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1.     <?php
  2.         require_once "./ProgramJAO.php";
  3.         $program = new ProgramJAO();
  4.         $program->main();
  5.         print_r($program->wynik);
  6.       ?>
  7.  
  8. <?php
  9.  
  10. /*
  11.  * To change this license header, choose License Headers in Project Properties.
  12.  * To change this template file, choose Tools | Templates
  13.  * and open the template in the editor.
  14.  */
  15.  
  16. /**
  17.  * Description of ProgramJAO
  18.  *
  19.  * @author student
  20.  */
  21. class ProgramJAO {
  22.     //put your code here
  23.     public $wynik;
  24.        
  25.        public function main(){
  26.          $zbiory = array(); //1
  27.          $zbior = array(); //1
  28.         $plik = fopen('dane.txt', 'r'); //3
  29.         $znaki = array(" ", "\t", "\r", "\n");
  30.         $noweZnaki = "";
  31.         if(FALSE ===$plik){
  32.             throw new Exception('Blad przy otwieraniu pliku');
  33.         }
  34.             while(FALSE === feof($plik)){//4
  35.                 $linia = fgets($plik, 4096);
  36.                 if(FALSE === $linia){//4.2
  37.                     break;
  38.                 }
  39.                 $linia = str_replace($znaki, $noweZnaki, $linia);//4.3
  40.                 $znak1 = substr($linia, 0, 1);
  41.                 $znakN = substr($linia, -1);
  42.                 if($znak1 !== "{" && $znakN !== "}"){//4.4
  43.                     break;
  44.                 }
  45.                 $linia = rtrim($linia, "{");//4.5
  46.                 $linia = ltrim($linia, "}");
  47.                
  48.                 $zbior = explode(",", $linia);//4.6
  49.                 $zbiory[] = $zbior;//4.7
  50.             }
  51.             fclose($plik);//5
  52.             $this->wynik = $zbiory;//6
  53.         }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement