Advertisement
Guest User

Untitled

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