Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Na dzisiaj przygotowałem coś prostego aczkolwiek bardzo przydatnego odczyt pliku tekstowego. Działania na plikach tekstowych są często potrzebne np. do przenoszenia danych z innych systemów.
Odczyt linia po linii przydaj się gdy w jednym pliku chcemy przesłać różne dane.
Więc na początek otwieramy plik, używamy trybu "r" czyli otwarcie tylko do odczytu z ustawieniem kursora na początku pliku.
$file = fopen("filename.txt", "r") or die("Unable to open file!");
aby pobrać jedną linię z pliku użyjemy
$row = fgets($file);
Jednak aby odczytać cały plik potrzebna jest pętla np while
while(!feof($file))
Jako warunku użyjemy funkcji feof sprawdzającej czy to koniec pliku z znakiem.! Czyli zaprzeczeniem tłumacząc na polski warunek brzmiałby "Jeśli nie koniec pliku".
Dobrze mamy wszystkie elementy a cały kod wygląda następująco:
$file = fopen("filename.txt", "r") or die("Unable to open file!");