title: PHP string containing line breaks causins problems when printing out Javascript
body: <p>I have a PHP string that contains an address and as such contains a few lines. One example could be:</p>
  
  <pre><code>$custDetails = "
  123 Main Street
  City
  Area Code
  ";
  </code></pre>
  
  <p>Although this address is retrieved using an SQL query, not declared in PHP.</p>
  
  <p>I would like to replace the go to line characters by something else, temporarily, to make modifying this string easier in another javascript function. But I'm running in to some problems. This code:</p>
  
  <pre><code>echo "
  &lt;script&gt;
    if ('$custDetails'.indexOf('\n') != -1)
       alert('yes');
    alert('$custDetails');
  &lt;/script&gt;
  ";
  </code></pre>
  
  <p>Becomes:</p>
  
  <pre><code>&lt;script&gt;
    if ('123 Main Street
  City
  Area Code'.indexOf('
  ') != -1)
    alert('yes');
    alert('123 Main Street
  City
  Area Code');
  &lt;/script&gt;
  </code></pre>
  
  <p>after treated by PHP. The "go to lines" in the string are treated as go to line in the script tag, and as such messes up the script. Additionally, I can't detect the \n char because it is treated as a go to line, and messes up the script...</p>
  
  <p>How can I make a string with multiple lines usable in javascript?</p>
  
  <p>EDIT: As suggested in one of the answers, I tried replacing "\n" with 'n' in PHP before calling the javascript</p>
  
  <pre><code>$custDetailsBis = str_replace("\n", '\n', $custDetails);
  
  echo "&lt;script&gt;
  alert(\"$custDetailsBis\");
  &lt;/script&gt;";
  </code></pre>
  
  <p>I still doesn't work, output in browser:</p>
  
  <pre><code>&lt;script&gt;
    alert("16 St Andrews Street
  \nDundee
  \nDD1 2EX");
  &lt;/script&gt;
  </code></pre>
  
  <p>Note that I know have \n that have appeared on the browser output, but there are still line breaks. Again the line breaks are causing errors in the javascript.</p>