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
Solved

php error with fgets()

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cpanel file manager 8 39
PHP Query return divisible by 3 3 25
jQuery Toggle & Anchor Links 5 42
PHP and MSSQL Arrays and Variables 3 22
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

789 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