Using strtr
is a tad faster than str_replace
or preg_replace
.
echo strtr($string,'|', "\n");
Mind the double quotes around the \n
.
Also, if you want to output HTML, a newline char is not sufficient, you need to replace it with
tags.
echo str_replace("|", "
\n", $string);