Solved

php error with fgets()

Posted on 2009-04-06
3
325 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

920 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

16 Experts available now in Live!

Get 1:1 Help Now