Replace a string in JavaScript and PHP
<p>How can I replace this character <code>|</code> in JavaScript?</p>

<pre><code>&lt;html&gt;
&lt;body&gt;

&lt;script type="text/javascript"&gt;

var str="data|data|data";
document.write(str.replace(/|/g,"&lt;br /&gt;"));

&lt;/script&gt;
</code></pre>

<p>
    </p>

<p>In the output of given code, every character has the "&lt; br />"</p>

<p>I don't know what is wrong with my code.. :)</p>

<p>Also, for PHP, I want the function to use if the input is</p>

<pre><code>|string||   
</code></pre>

<p>and the output should be </p>

<pre><code>string
</code></pre>

<p>only. I want only the outer part of the string in PHP to be subtituted: <code>||hel||lo||</code> would become <code>hel||lo</code>.</p>

<p>Could I use <code>trim()</code>? I think <code>trim()</code> only applies to white spaces.</p>
