read text file in php line by line code example
Example 1: php read file line by line
$handle = fopen("inputfile.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
}
fclose($handle);
} else {
}
Example 2: .php file
<html>
<head>
<title>Reading a file using PHP</title>
</head>
<body>
<?php
$filename = "abc.txt";
$file = fopen( $filename, "r" );
if( $file == false ) {
echo ( "Error in opening file" );
exit();
}
$filesize = filesize( $filename );
$filetext = fread( $file, $filesize );
fclose( $file );
echo ( "File size : $filesize bytes" );
echo ( "<pre>$filetext</pre>" );
?>
</body>
</html>
//This is a php File Yes!!!!!