Using strtr less than str_replace or preg_replace .
echo strtr($string,'|', "\n");
Note the double quotes around \n .
In addition, if you want to output HTML, then char is not enough for a new line, you need to replace it with <br /> tags.
echo str_replace("|", "<br />\n", $string);
chiborg
source share