Using str_replace to add <p> tags to an article

Can someone point out why extra <p></p> tags are being inserted at the end of each paragraph? Here is my code:

$paragraphTags = str_replace("
", “</p>
<p>”, ‘<p>’.$testimonialText.‘</p>’);

Here is the result:

<p>This is a follow-up to the bulletin we sent on September 12. It has come to our attention that some merchants may have received emails where the sample code snippets had syntax errors. We would like to apologize for the inconvenience and make sure we publish the corrected code snippets. Additionally, some merchants reported that their IPN scripts updated to use HTTP 1.1 get “hung” or take a long time to get a ‘VERIFIED’ response. We are including instructions on how to remedy this issue as well by adding "Connection: close” header in the HTTP request.
</p>
<p>
</p>

Because you had an extra
type of line end that existed, but you could not see it, because it displays nothing. They’re clever like that.

Because you told it to…

Take this into consideration, let’s say you have "This is a test
" as your $testimonialText.

Here is what you coded:
Given: ‘<p>This is a test
</p>’
Replace ’
’ with ‘</p>
<p>’
Result: ‘<p>This is a test</p>
<p></p>’

One way to solve it is to use trim()

$paragraphTags = str_replace("\
", "</p>\
<p>", '<p>'.trim($testimonialText, "\
").'</p>');

Is there something else I might be missing? I implemented your example, cpradio, and still it’s showing the extra <p></p> tags.

And does it make a difference that I’m coding on a Mac instead of PC?

Here is the code I have and it works.

<?php
    $paragraphTags = "This is a test\
";
    $paragraphTags = str_replace("\
", "</p>\
<p>", '<p>'.trim($paragraphTags, "\
").'</p>');
    var_dump($paragraphTags);
?>

You can also try it with preg_replace to replace carriage returns and newlines

<?php
  $paragraphTags = "This is a test\\r\
";
  //$paragraphTags = str_replace("\
", "</p>\
<p>", '<p>'.trim($paragraphTags, "\
").'</p>');
  $paragraphTags = preg_replace("/(\\r\
|\\r|\
)/", "</p>\
<p>", '<p>'.trim($paragraphTags, "\\r\
").'</p>');
  var_dump($paragraphTags);
?>