title: PHP - Echo new line character "\n" as single quote string
body: <p>How can I echo the new line character \n as if it was in a single quote string?</p>
  
  <pre><code>$foo = 'foo';
  $nl = getStringWithNewLineCharacter();
  $bar = 'bar';
  
  echo $foo . $nl . $bar;
  </code></pre>
  
  <p>will output :</p>
  
  <pre><code>foo
  bar
  </code></pre>
  
  <p>What I want is :</p>
  
  <pre><code>foo\nbar
  </code></pre>
  
  <p>(Obviously, I do not control the return value of the getStringWithNewLineCharacter() function.)</p>
  
  <p>Or said differently, how can I force a variable to be interpreted as a single quote string?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>While answers provided gave a workaround, the real question here is how to interpret a double quoted string variable as a single quoted string variable. Maybe it's not possible, I don't know. To answer this, it requires understanding of how the interpreter manages string variables (which I lack).</p>
  
  <p>So :</p>
  
  <ul>
  <li>How is the "quote type" of a string defined?</li>
  <li>Is it immutable?</li>
  <li>Is there a way to change how the interpreter will manage a string variable?</li>
  </ul>