Solved

php error with fgets()

Posted on 2009-04-06
3
322 Views
Last Modified: 2013-12-13
Hi there,

I have already posted a similar question. The error i aim getting here is regarding the fgets function. I belive the code is  ok but i get the error: Warning: Wrong parameter count for fgets() in c:\apache\htdocs\test.php on line 15. Can you please test code and let me no how to fix error? I have pasted the code below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Read and display file content</title>
</head>
<body>

<?php
//header("Content-type: text/plain");
$fileName = "testReadFile.txt";
$file = fopen($fileName, "r") or exit("Unable to open file!");
while(!feof($file))  
{
  echo fgets($file). "<br />";
}

fclose($file);
?>

</body>
</html>

Speedy response is as always very much appreciated!
0
Comment
Question by:motolanix1
3 Comments
 
LVL 8

Accepted Solution

by:
mostart earned 250 total points
Comment Utility
fgets does have a second parameter "length" :

from http://de3.php.net/fgets:
string fgets  ( resource $handle  [, int $length  ] )  

This second parameter has become optional (defaults to 1024 bytes) with PHP version 4.2.0.

what version of PHP are you using ?
0
 

Author Closing Comment

by:motolanix1
Comment Utility
I am using version php triad 2.2.1. I mean does the code seem right to you and is there any way to resolves this. Perhaps if the code was rewritten differently?
0
 
LVL 14

Expert Comment

by:shobinsun
Comment Utility
Hello,

This error is because of your PHP version.

Your PHP version is below 4.3.0.

Its works fine in PHP 5 upto PHP 4.3.0.

Until PHP 4.3.0, omitting it would assume 1024 as the line length.

so please do with

 echo fgets($file, $length);

Regards.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now