U3F1ZWV6ZTc5OTgzNDMxMzE1MzJfRnJlZTUwNDYwNDY0NzA3Nzc=

How to read all ligne of a file using php ?

How to read all ligne of a file using php,count,file


Question :  
 how to read all ligne of a file using php language ? 
i try this :
$handle = fopen("inputfile.txt");

Solution : 

file (PHP 4, PHP 5, PHP 7) file - Read the file and return the result in an array 
Description file (string $ filename [, int $ flags = 0 [, resource $ context]]): array 

 count (PHP 4, PHP 5, PHP 7) count - Counts all the elements of an array or something of an object

Description 

count (mixed $ array_or_countable [, int $ mode = COUNT_NORMAL]): int

 // Name of the file to open     

 $ file = file ("YourFile.txt");    
  
// Total number of lines in the file   
   
$ total = count ($ file);      

 for ($ i = 0; $ i <$ total; $ i ++) {     
// We display line by line the content of the file      
// with the nl2br function to add line breaks      
echo nl2br ($ file [$ i]);      
}      

// OR by having line numbers and adding line breaks      
// Display all the rows of the table      
// with line numbers      
foreach ($ file as $ line_num => $ line) {     
    
 echo "Line # <b> {$ line_num} </b>:". htmlspecialchars ($ line). "<br /> \ n";

}


if you want to improve the solution
comment to help the community
Comments
No comments
Post a Comment

Post a Comment

NameEmailMessage