Parsing Line Breaks in PHP/JavaScript
<p>EDIT: Ok, thanks for your help guys. Using zerkms' suggestion, I have managed to get <code>&lt;br&gt;</code> tags inserted instead of carriage returns, so it is displayed properly on the page and doesn't break the javascript. The problem is now that when the user clicks on this text, it becomes a textarea and is therefore inline editable. However, the text string now has the tags displayed in it, rather than just having the editable text over multiple lines.</p>

<p>Any suggestions?</p>

<p>ORIGINAL QUESTION: I have a text area in my PHP application where users can enter notes in a project. Sometimes this is displayed on the page via PHP and sometimes it is displayed via javascript. The problem is, if the note is across multiple lines (i.e. the user presses enter while entering notes in the text area), it causes the JS to fail. It's fine when it's being done by the PHP.</p>

<p>The line of code in question is:</p>

<pre><code>var editnotes='&lt;textarea class="desc_text" style="width:20em;" id="notes_editor"&gt;&lt;?php print $notes; ?&gt;&lt;/textarea&gt;';
</code></pre>

<p>So, if the note is over multiple lines, the PHP builds the pager as:</p>

<pre><code>var editnotes='&lt;textarea class="desc_text" style="width:20em;" id="notes_editor"&gt;This is
a test note
over multiple lines
&lt;/textarea&gt;';
</code></pre>

<p>And this obviously causes problems for the js. So my question is, what can I do to prevent this? As the code is being built by PHP before it even gets to the browser, I'm thinking that the best approach may be to parse it in the PHP so that the output is something more like this:</p>

<pre><code>var editnotes='&lt;textarea class="desc_text" style="width:20em;" id="notes_editor"&gt;This is&lt;br/&gt;a test note&lt;br/&gt;over multiple lines&lt;br/&gt;&lt;/textarea&gt;';
</code></pre>

<p>Will this work? How would I do it?</p>

<p>Thanks</p>
