How can I replace this character `|` in JavaScript?

```
<html>
<body>

<script type="text/javascript">

var str="data|data|data";
document.write(str.replace(/|/g,"<br />"));

</script>

```

In the output of given code, every character has the "< br />"

I don't know what is wrong with my code.. :)

Also, for PHP, I want the function to use if the input is

```
|string||   

```

and the output should be 

```
string

```

only. I want only the outer part of the string in PHP to be subtituted: `||hel||lo||` would become `hel||lo`.

Could I use `trim()`? I think `trim()` only applies to white spaces.