PHP Tutorial : Read file with php

Reading the contents of a file with php is made via read php fread() function. Additionally we need to use other to functions for opening the file called fopen() and to close it with fclose(). PS : the f from the front of the functions comes from File. Here is an example of usage :

<?php
$textFiletoRead = "readFromThis.txt";
$openTheFile = fopen($textFileToRead, 'r');
$sizeOf = filesize($textFiletoRead);
$textContentsInFile = fread($openTheFile, $sizeOf);

fcolse($textContentsInFile);
print $textContentsInFile;
?>
This entry was posted in Basic PHP and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>