Jump to content

Reading past whitespace


vWithQuestion

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.