bhayes Posted January 18, 2007 Share Posted January 18, 2007 Hello! I'm having trouble getting line breaks during the output portiong in a bit of code I've written/cobbeled together. The jist is that a form submits name/value pairs to this php script, it then takes the pairs, and then saves it to another file. That file will eventually be a file of JS variables, each of which needs to be on a new line. The script will out put the variables, and even display them on new lines using <br>, but in the new file they all run together. You can see it in action at http://www.hayesweddingphoto.com/other/setup.htmlHere is the script:[code]<?function form_handler() { global $HTTP_POST_VARS; reset($HTTP_POST_VARS); $http_vars = ""; while(list($name, $value) = each($HTTP_POST_VARS)) $http_vars .= $name . " = " . $value . "<br>"; return($http_vars); }; $content = form_handler(); $filename = 'settings2.txt';// Let's make sure the file exists and is writable first. if (is_writable($filename)) { if (!$handle = fopen($filename, 'w+')) { echo "Cannot open file ($filename)"; exit; } // Write $http_vars to our opened file. if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote: <br> <br> $content <br>to file $filename"; fclose($handle);} else { echo "The file $filename is not writable";}?>[/code]As I said, while the browser displays it correctly, the settings2.txt file shows the following:[code]galleryIndex = http://www.hayesweddingphoto.com<br>introTextfile_section = 1<br>submit = submit<br>[/code]Thanks for any help you might give! Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 18, 2007 Share Posted January 18, 2007 It's a text file, not html. Use \n not br Quote Link to comment Share on other sites More sharing options...
bhayes Posted January 18, 2007 Author Share Posted January 18, 2007 sorry...I should have mentioned that \n gives the same result. Quote Link to comment Share on other sites More sharing options...
bhayes Posted January 18, 2007 Author Share Posted January 18, 2007 ok... \n works when the file name is settings.txt, however when I change the file name to settings.js it no longer works. I still get the output from above. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 18, 2007 Share Posted January 18, 2007 Mrph...what happens with \r\n?What happens if at the end of the lines, you add .'';Like actually hit the enter key in your code? I'm just tossing out random stuff...good luck. Quote Link to comment Share on other sites More sharing options...
fiat Posted January 18, 2007 Share Posted January 18, 2007 what are you reading the file with?sometimes this is a quirk in some text editors - they do not recognise/parse the /n and output the data in continuous fashion for certain file types... Quote Link to comment Share on other sites More sharing options...
bhayes Posted January 18, 2007 Author Share Posted January 18, 2007 Ok... \r\n gives the correct appearance, but the file does not then opperate correctly (as if the line breaks are not there.) This did not work at all (unexpected ' I think was the error):.'';basically this is a settings file that will be read by an HTML page, the values inserted into the form so that the user can view/update them, then the process.php file resaves the values to the same file. I'm reading (viewing) the files with notepad. Quote Link to comment 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.