Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fgets problem

Status
Not open for further replies.

Greenster

Programmer
Jan 14, 2002
30
GB
Hi,

Can anyone help me - I use fopen to open a txt file it always returns success.
I fopen with a "a+" as I need to read and write.

When I use
while($buffer = fgets($fp , 4096)){

}

It returns one blank line and quits the line.
I have also used
while (!feof ($fp)){
$buffer = fgets($fp , 4096)
}

same thing, one blank line. Permissions are fine am using Linux OS.

I know definitely 100% that the file contains text!! (5 lines) Why does it return one blank line and quit the loop??

Any help would be appreciated.

Cheers

{Greenster}
 
You have to do a rewind on the File.

'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

After the fopen you must do
rewind($fp)

Other thing, you can open the file as "r+". With this flag you can read and write in the file, but it opens in the BOF instead of EOF.


Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanx Anakin, worked a treat. I should have spotted that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top