Free Computer Based Training, E-learning, CBT and IT Training courses.
php file read tutorial, php file write tutorial, php r/w tutorial, read write tutorial php.Try our free video tutorials training courses.
Online computer training and distance learning online tutorials
php file read tutorial, php file write tutorial, php r/w tutorial, read write tutorial php Online Training

Microsoft Office TrainingMicrosoft Office Skills Training
Business Skills Courses Business Skills Courses

Technical Courses Technical Courses

Networking Networking Training Courses

Java PHP C C++ Perl Training Java PHP C C++ Perl Training

Web Marketing Training Web Marketing Training

Database Training Database Training

Unix Training Unix Training

Online Aptitude Testing and computer Assessments Online Aptitude Testing and Assessments.

Personal Development Training Personal Development Training

Try our online computer training courses via distance learning.
php file read tutorial, php file write tutorial, php r/w tutorial, read write tutorial php Free Video Tutorials

Free video tutorials for Adobe photoshop. Adobe Photoshop
Free video tutorials for Dreamweaver. Dreamweaver
Free video tutorials for Flash. Flash
Free video tutorials for Html. Html
Free video tutorials for visual basic. Visual Basic
Free video tutorials for Perl. Perl
Free video tutorials for C++. C & C++

free IT Training and e-learning computer based training courses.
Online Training Assessments


Technical Courses Verbal Reasoning

aptitude Numerical Reasoning

Free Online Java Quiz

Online Computer Training, e-learning, free video tutorials.
Online Training Training Tools

free IT Training and e-learning courses. Course Manager
Try our online computer training courses and our e-learning cbt courses. System Manager


Computer Training & Webmaster forum - internet marketing and search engine forum
  

Click here to register for your free computer training courses.

Web Diretory | Sitemap | Blog

Try learningsteps.com online computer training courses and tutorial via online learning, online training.

PHP File Read/Write Tutorial:


PHP Reading form a File?

In PHP it is relatively easy to read from a file.

PHP has inbuilt function called fgets() that allows us to read lines from files

Example:
fgets ($handle, $length);

As you can see from the above pseudo code fgets excepts two parameters

(1) $handle - the file pointer
(2) $length - An integer to tell the function how much data, in bytes, it is supposed to read.
(Note 1 character is the equivalent of one byte - so if we wanted to read 10 characters then we would use fread($fh, 10);)


Lets now create a sample:

<?php
$myFile = "readFile.txt";
$fh = fopen($myFile, 'r');
$outputFileContents = fread($fh, 10);
fclose($fh);

echo $outputFileContents;
?>

'R' denotes that we want to open the file in read mode.

The $fh variable contains the file handle for testFile.txt. The file handle knows the current file pointer, which for writing, starts out at the beginning of the file.

In PHP if you wanted to read all data that is stored in a file, then you need to get the size of the file. The filesize function returns the length of a file, in bytes.

<?php
$myFile = "readFile.txt";
$fh = fopen($myFile, 'r');
$fs=filesize($myFile);
$outputFileContents = fread($fh, $fs);
fclose($fh);
echo $outputFileContents;
?>

Another way is too loop through the contents of the file line by line until you reach the end of the file

<?php
$file = "readFile.txtt";
$fp = fopen($file, "r");
while(!feof($fp)) {
	$outputFileContents = fgets($fp, 2024);
	echo "$outputFileContents 
"; } fclose($fp); ?>

free online unix tutorial
CBT
online computer courses

Copyright ©2007 LearningSteps.com Inc. Computer Based Training | E-Learning | CBT | IT Training

free IT Training and Cbt computer based training courses.

try our paid computer based training(cbt) or free computer training