Jump to content

is it possible?


specialguy

Recommended Posts

I use this code to show many time a page has been view and i know that fgets only take the first line of the file.

<?php$monfichier = fopen('compteur.txt', 'r+');$pages_vues = fgets($monfichier)$pages_vues++;  fseek($monfichier, 0); fputs($monfichier, $pages_vues); fclose($monfichier);echo '<p>This page has been seen' . $pages_vues . ' time !</p>';?>

My question is: is there a way to read more than the first line and not using While? (like an easy way to read lots of lines)Thanks.

Link to comment
Share on other sites

If the file is not too big, you can use file_get_contents to get the whole thing. Other then that, there's no way to read more then one line at once, unless you know the length of each line. If you know that all lines are 100 characters long, then you can use fread to read 300 bytes, which would get 3 lines. But, if you don't know how long the lines are, then you need to use a loop to get them one at a time.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...