title: Avoid new lines in csv because of carriage return with php
body: <p>doing my few first steps in PHP and I'm stuck. Been searching SO all afternoon but couldn't come up with a solution. Highly appreciate any advice from experienced devs.</p>
  
  <p><strong>Scenario:</strong>
  Users are asked to fill out a short survey consisting of two textareas. Upon hitting the submit button, the content of the textareas is written to a csv file.</p>
  
  <p><strong>Problem:</strong>
  My problem is that (while it does write the content) whenever people use carriage return in the textarea, it results in a new line in the csv file, thus messing it up. I've spent the afternoon reading up on stackoverflow and trying to use str_replace(); for rewriting all \n with spaces " ", alas to no avail.</p>
  
  <p>Here is my <strong>HTML</strong>:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt; 
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Survey name here&lt;/title&gt;
  &lt;meta charset='utf-8'&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;?php
  if(!empty($errorMessage)) 
  {
  echo("&lt;p&gt;Error!&lt;/p&gt;\n");
  echo("&lt;ul&gt;" . $errorMessage . "&lt;/ul&gt;\n");
  } 
  ?&gt;
  
  &lt;div id="content"&gt;
  &lt;h1&gt;Survey&lt;/h1&gt;
  
  &lt;form action="post.php" method="post" id="survey"&gt;
  
  &lt;p&gt;&lt;strong&gt;Question 1:&lt;/strong&gt;&lt;br /&gt;Do you like it or not?&lt;/p&gt;
  &lt;p&gt;&lt;textarea rows="6" cols="100" name="question1" value="&lt;?=$answer;?&gt;"&gt;&lt;?php echo $answer ?&gt;&lt;/textarea&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;strong&gt;Question 2:&lt;/strong&gt;&lt;br /&gt;Would you prefer this or that?&lt;/p&gt;
  &lt;p&gt;&lt;textarea rows="6" cols="100" name="question2" value="&lt;?=$answer2;?&gt;"&gt;&lt;?php echo $answer2 ?&gt;&lt;/textarea&gt;&lt;/p&gt;
  
  &lt;input type="submit" name="formSubmit" value="Submit" id="submit" onclick="return Validate()"/&gt;
  &lt;/form&gt;
  &lt;/div&gt;&lt;!-- End Content --&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is the <strong>PHP</strong> part:</p>
  
  <pre><code>&lt;?php
  if($_POST['formSubmit'] == "Submit")
  {
  $answer1 = $_POST['question1'];
  $answer2 = $_POST['question2'];
  
  // report error when not answered
  $errorMessage = "";
  if(empty($_POST['question1']))
  {
  $errorMessage .= "&lt;li class='errormsg'&gt;Please answer the question No. 1!&lt;/li&gt;";
  }
  if(empty($_POST['question2']))
  {
  $errorMessage .= "&lt;li class='errormsg'&gt;Please answer the question No. 2!&lt;/li&gt;";
  }
  
  // sending to CSV
  if(empty($errorMessage)) 
  {
  str_replace('\r\n', ' ', $answer1 . $answer2);
  $fs = fopen("test.csv","a");
  fwrite($fs,$answer1 . ";" . $answer2 . "\n");
  fclose($fs);
  
  // after submit, head to thank you page 
  header("Location: thankyou.php");
  exit;
  }
  }
  ?&gt;
  </code></pre>
  
  <p>I figure I'm not applying the str_replace() function correctly. Who can help me?</p>