Solved

php error with fgets()

Posted on 2009-04-06
3
331 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
ID: 24076048
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
ID: 31566962
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
ID: 24076107
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

685 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