How to remove line breaks with PHP or JS
<p>I've tried about everything to delete some extra <code>\n</code>  characters in a web application I'm working with. I was hoping someone has encountered this issue before and knows what can be causing this. All my JS and PHP files are UTF-8 encoded with no BOM.</p>

<p>And yes I've tried things like</p>

<p>In JS:</p>

<pre><code>text.replace(/\n/g,"")
</code></pre>

<p>In PHP:</p>

<pre><code>preg_replace("[\n]","",$result);
str_replace("\n","",$result);
</code></pre>

<p>and when I try </p>

<pre><code> text.replace(/\n/g,"")
</code></pre>

<p>in the firebug console using the same string I get from the server it works but for reason it doesn't work in a JS file.</p>

<p>I'm desperate, picky and this is killing me. Any input is appreciated.</p>

<p><strong>EDIT:</strong></p>

<p>If it helps, I know how to use the replace functions above. I'm able to replace any other string or pattern except <code>\n</code> for some reason.</p>

<p><strong>Answer Explanation:</strong></p>

<p>Some people do and use what works because it just works. If you are like me and for the record I always like to know why what works WORKS!</p>

<p>In my case:</p>

<p>Why this works?   <code>str_replace('\n', '', $result)</code></p>

<p>And this doesn't?   <code>str_replace("\n", '', $result)</code></p>

<p>Looks identical right?
Well it seems that when you enclose a string with a character value like <code>\n</code> in double quotes <code>"\n"</code> it's seen as it's character value NOT as a string. On the other hand if you enclose it in single quotes <code>'\n'</code> it's really seen as the string <code>\n</code>. At least that is what i concluded in my 3 hours headache.</p>

<p>If what I concluded is a setup specific issue OR is erroneous please do let me know or edit. </p>
