vWithQuestion Posted November 3, 2013 Share Posted November 3, 2013 Doing a simple readline from text file using $TheLine = fgets($file). It works, but it will only read up to the first space character in the line. Is there a way to read the spaces (if present) in a line read? Quote Link to comment https://forums.phpfreaks.com/topic/283565-reading-past-whitespace/ Share on other sites More sharing options...
Ch0cu3r Posted November 3, 2013 Share Posted November 3, 2013 It works, but it will only read up to the first space character in the line By that do you mean a new line character? Quote Link to comment https://forums.phpfreaks.com/topic/283565-reading-past-whitespace/#findComment-1456765 Share on other sites More sharing options...
Barand Posted November 3, 2013 Share Posted November 3, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283565-reading-past-whitespace/#findComment-1456778 Share on other sites More sharing options...
vWithQuestion Posted November 3, 2013 Author Share Posted November 3, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283565-reading-past-whitespace/#findComment-1456784 Share on other sites More sharing options...
Solution Barand Posted November 3, 2013 Solution Share Posted November 3, 2013 attribute values need to be in quotes, otherwise it will only include the first word <input type="text" name="First" value="<?=$FirstLine?>"> Quote Link to comment https://forums.phpfreaks.com/topic/283565-reading-past-whitespace/#findComment-1456785 Share on other sites More sharing options...
vWithQuestion Posted November 3, 2013 Author Share Posted November 3, 2013 attribute values need to be in quotes, otherwise it will only include the first word <input type="text" name="First" value="<?=$FirstLine?>"> You are a genius. That was it... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/283565-reading-past-whitespace/#findComment-1456792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.