Jump to content

adding line breaks to output text file


bhayes

Recommended Posts

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.html

Here 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!
Link to comment
Share on other sites

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.


Link to comment
Share on other sites

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.