title: Remove carriage return from form before writing to csv
body: <p>I have a php form that sends the results to an email and also writes to a csv file on the server that I download to use in openoffice calc.</p>
  
  <p>The mailing works fine, and so does the writing except one aspect:
  when people use the "enter" key (carriage return, right?) the new line is seen as another cell in openoffice calc, or if I open the file using notepad++ I see the lines of the same field on different lines.</p>
  
  <p>How can I clean it up so that the content of the text area displays in its single cell?</p>
  
  <p>I had the problem when people used commas in the fields, so I change commas with pipes, and that seems to have fixed that part.</p>
  
  <p>Here is the code to write into the csv file I am using, in case you need some more of the code, please let me know.</p>
  
  <pre><code>$fp = fopen('/path-to-file/data.csv', 'a');
  fwrite($fp, $name . '|' . $lastname . '|' . $address . '|' . $city . '|' . $country . '|' . $email . '|' . $phone . '|' . $messageone . '|' . $messagetwo . '|' . $comment . '|' . PHP_EOL);
  fclose($fp);
  </code></pre>
  
  <p><em>UPDATE ONE</em></p>
  
  <p>@Marco
  Thank you for the code, I thought it was not related, but in the full code I do have the trim function, and it doesn't seem to do it, following is a more complete code of the processing file, file ends with the code to send the email messages to user, and admin - I removed many fields, but they are basically the same as the ones posted, as you can guess.</p>
  
  <pre><code>    $required = array('name','lastname','address','city'); // more fields here
      $all_okay = TRUE;
      $clean_post = array();
      $error = '';
      foreach($required as $key) {
          if (empty($_POST[$key])){
              $error .= "&lt;br/&gt;$key is a required field\n";
              $all_okay = FALSE;
          }else{
              $clean_post[$key] = $_POST[$key];
              $_SESSION[$key] = $_POST[$key];
          }
      }
  
      //Name
      }elseif(!preg_match("/^[a-zA-Z' -]{2,}/", trim($_POST['name']))){
          $error .= "&lt;br /&gt;&lt;strong&gt;Name does not pass validation&lt;/strong&gt;\n";
      //Lastname
      }elseif(!preg_match("/^[a-zA-Z' -]{2,}/", trim($_POST['lastname']))){
          $error .= "&lt;br /&gt;&lt;strong&gt;Lastname does not pass validation&lt;/strong&gt;\n";
      //Address
      }elseif(!preg_match("/^[a-zA-Z0-9' -]{2,}/", trim($_POST['address']))){
          $error .= "&lt;br /&gt;&lt;strong&gt;Address does not pass validation&lt;/strong&gt;\n";
  
      //Continue if no error
      }elseif(empty($error)){ 
  
          // PREPARE THE DATA 
          $name = Trim(stripslashes($_POST['name']));
          $lastname = Trim(stripslashes($_POST['lastname']));
          $address = Trim(stripslashes($_POST['address']));
          $city = Trim(stripslashes($_POST['city']));
  
  // write to csv file
  $fp = fopen('/path-to-file/data.csv', 'a');
  fwrite($fp, $name . '|' . $lastname . '|' . $address . '|' . $city . '|' . $country . '|' . $email . '|' . $phone . '|' . $messageone . '|' . $messagetwo . '|' . $comment . '|' . PHP_EOL);
  fclose($fp);
  
          // PREPARE EMAIL BODY TEXT
          $body = '';
          $Admin_body = '';
  </code></pre>
  
  <p><em>UPDATE TWO</em></p>
  
  <p>@Marco
  Thank you, the debugger displays the same way, with the "error".
  I might have found the culprit, though I don't know how to solve it, but you might.
  The problem is there are not text delimiter, besides the field delimiter.</p>
  
  <p>I tried adding this, but while email goes thru the file is not written on.</p>
  
  <pre><code>fwrite($fp, '"' . $name . '"|"' . $lastname . '"|"' . $address . '"|"' . $city . '"|"' . $country . '"|"'
  </code></pre>
  
  <p>I cut the code, but did it to the last field (comment).
  And I also didn't put all the trimmed fields, but they are all trimmed.</p>
  
  <p>The idea of the text delimiter is from here:
  <a href="https://forum.openoffice.org/en/forum/viewtopic.php?f=9&amp;t=76545&amp;p=348709#p348709" rel="nofollow">https://forum.openoffice.org/en/forum/viewtopic.php?f=9&amp;t=76545&amp;p=348709#p348709</a></p>
  
  <p><em>UPDATE THREE</em></p>
  
  <p><strong>OK, this is the solution for others if encounter same problem</strong>
  The last snip was on the right track, but I had an error in it, pipe and quote mark at the end, and I added EOL.</p>
  
  <pre><code>fwrite($fp, '"' . $name . '|' . $lastname . '|' . $address . '|' . $city . '|' . $country . '|' . $email . '|' . $phone . '|' . $messageone . '|' . $messagetwo . '|' . $comment . '"' . PHP_EOL);
  </code></pre>
  
  <p>Thank you Marco, your help, and patience greatly appreciated.</p>