473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

fgets working explaination

pradeepjain
563 512MB
[PHP]<?php
$handle = fopen("welcome.txt", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle);
echo $buffer;
echo "<br>";
}
fclose($handle);
}
?>
[/PHP]


this is working as needed for me but i am not getting how it works.. i know tht fgets gets the string of length specified .i am not able to know here how it goes to next line automatically by itself .can any one please explain this to me plzz...


Thanks,
Pradeep
Apr 3 '08 #1
3 1224
ronverdonk
4,258 Expert 4TB
Would be easier if you just read the PHP documentation on the fgets() command
Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line.
Ronald
Apr 3 '08 #2
Atli
5,058 Expert 4TB
Hi.

Yea, the documentation pretty much explains it all.

If it is sill confusing, consider how you code is being interpreted:
Expand|Select|Wrap|Line Numbers
  1. while ( we havent reaced the end of the file) {
  2.   Read one line into the buffer;
  3.   Print the buffer;
  4.   Print <br />
  5. }
  6.  
Apr 3 '08 #3
aktar
105 100+
basically the fgets() command read a new line everytime its called. So if its on line 1 now, it will read line 2 the next time it is called, very similar to navigating through an array with the next() command
Apr 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Adam Bergman | last post by:
Okay, I am working on a credit card validation script, I have it working perfectly (saving the return information from the server to a variable and echoing it for now) other than this weird error...
3
by: Alex Shi | last post by:
Hi all, Please take a look at following very simple script; #!/usr/bin/php -q <? echo "Hello, world!\n"; if (!$tty) { $tty = fopen('php://stdin', 'r'); }
2
by: Diego | last post by:
Hi, Using gcc 2.96 This message was suggested by a thread started by Knak on 21/03/04 The question is: When I run the following code, if I want to introduce a second pile of data, the...
20
by: TTroy | last post by:
Hello, I have found some peculiar behaviour in the fgets runtime library function for my compiler/OS/platform (Dev C++/XP/P4) - making a C console program (which runs in a CMD.exe shell). The...
32
by: FireHead | last post by:
Hello C World & Fanatics I am trying replace fgets and provide a equavivalant function of BufferedInputReader::readLine. I am calling this readLine function as get_Stream. In the line 4 where...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
7
by: CaptainnFungi | last post by:
Hi All, I am very new to C and have been working my way through a few C books with the aim of getting more knowledge in programming. However I have hit a wall and I am not sure how to get over it....
3
by: Shisou | last post by:
Hey bytes community! this one is a really strange issue I ran into and I'm hoping you all can shine some light on it for me. This is written in C, not C++ I'm working on a program that reads...
6
by: Gert Kok | last post by:
When fgets() reads a string that ands with <<<EOT, the string is truncated after << and a lot of following input is discarded. When <<<EOT is changed to <<< EOT, behaviour is as I expect it. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.