Jump to content

Reading past whitespace


Go to solution Solved by Barand,

Recommended Posts

from manual for fgets()

 

 

 

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.

 

Nothing about stopping at space characters.

This is a super simple / cheesy page for a project that reads a line at a time to populate an output web page. I know there is probably better ways to do it but I am limited to php on this particular site. To read the data I have:

$file = @fopen('data.txt',"r");
$FirstLine = fgets($file);
$SecondLine = fgets($file);
etc...

The data file would have simple data like:

 

This is the first line

The second line

The output just populates text boxes:

<input type="text" name="First" value=<?=$FirstLine?>>
etc...

When the output is displayed, the first textbox only contains the word: This

The second textbox only contains the word: The

 

The code to write the data to the file is:

$filename = "data.txt";
$fp = fopen($filename, "w");

fwrite($fp, $_POST["First"]);
fwrite($fp, "\n");
etc...
fclose($fp);

It is not critical, but I was just wondering

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.