PHP Scripting
Read File
Read file using PHP function fread and fscanf
By Geekboots
6/25/2020
0 views
read-file.phpPHP
<?php
$fname = "myFile.txt";
/* Get file size */
$fsize = filesize($fname);
/* Open file in read mode */
$file = fopen($fname, "r" );
/* Read file using 'fread' */
$data = fread($file, $fsize );
echo $data."<br />";
/* Close file */
fclose($file);
/* Open file in read mode */
$file2 = fopen($fname, "r");
/* Parses input from a file according to a format using 'fscanf' */
while ($info = fscanf($file2, "%s %s %s\n")) {
/* List according to reading format */
list($p1,$p2,$p3) = $info;
echo $p1." ".$p2." ".$p3."<br />";
}
/* Close file */
fclose($file2);
?>
/* Ouput */
My first file! This is a text file!
My first file!
This is a
PHPread file using PHPfread functionfscanf function