Double results when using str_replace

I am confused why the following code returns two X’s between each paragraph. I was expecting only one.

$paragraphs = str_replace("
“, “X”, $paragraphs);

So then I figured there must be two line breaks in the text coming from the database. But when I tried the following code, there was no X at all between each paragraph.

$paragraphs = str_replace(“

“, “X”, $paragraphs);

I’m clearly not understanding about something regarding line breaks. If it makes any difference, I’m working on a Mac, and I think they handle line breaks differently than a PC.

Chances are there were other bits stored in between the multiple
's, which is why your second attempt didn’t insert any X’s.

When dealing with line breaks, I like to use preg_replace, because you can generally define a catch for all systems by using

$paragraphs = preg_replace("/(\\r\
|\\r|\
)/", "X", $paragraphs);

It will attempt to find \r
together, or a single \r or a single
, thus covering the typical Operating System end lines.

You can also use the PHP_EOL constant. It will give you the line ending for the current platform.

It’s still not working for me, and I even tried adding two
’s like this, [LEFT]/(\r
|\r|

)/
[/LEFT], in your preg_replace example. So that I can get this resolved, is there a way to force the text to show these “hidden” bits that are in the paragraph text? Thanks cpradio!

Have you tried echoing nl2br( $paragraphs );