Read a Text File With PHP
Read a Text File With PHP, the below Code Snippet show how to read content inside a file via PHP .
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <?php // Open the File $file = fopen ( "C:/xampp/htdocs/testFile.txt" , "r" ); $i =0; // as long as is not end of file continue loop through while (! feof ( $file )){ // get the file string by line $thisLine = fgets ( $file ); // Explode the line when there is a ", " in between $personData [ $i ]= explode ( "," , $thisLine ); $i ++; } // close the File fclose( $file ); // Number of Rows $numRows = sizeof( $personData ); // Loop Through the Array and print out for ( $x = 0; $x < $numRows ; $x ++) { for ( $y = 0; $y <sizeof( $personData [ $x ]); $y ++) { echo $personData [ $x ][ $y ]. "," ; } echo "<br>" ; } ?> |