Lire un fichier ligne par ligne en php
Rédigé par BeHuman
Aucun commentaire
Classé dans : Php

Voilà quelques fonctions qui pourraient vous être utile pour lire un fichier ligne par ligne en PHP...bref rien de bien méchant
//return fileobject function loadTXT($filename) { return fopen($filename, 'r'); } //return array function readAllTXT($handle) { $txt=array(); if ($handle) { while (!feof($handle)){ $buffer = fgets($handle); $txt[]= $buffer; } fclose($handle); return $txt; } } //return string function readLineTXT($handle, $number) { $i=1; if ($handle) { while (!feof($handle)){ if ($i==$number){ return fgets($handle); } $i++; } } } //no return function closeTXT($handle) { if ($handle) { fclose($handle); } }
++