Solved

php error with fgets()

Posted on 2009-04-06
3
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Suggested Solutions

Title # Comments Views Activity
Why is my implode function empty 8 41
&& operators not performing required logic 8 39
Php variable to be sent back 3 30
Centos webserver sending tons of spam 27 32
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

737 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