-1

So I have the the following html:

line 1<br>line 2<br><br>line 4<br><br>line 6 

And a preg_replace that replaces all break lines with new lines:

preg_replace('#<br\s*/?>#i', "\n", $data.edit_comment->content)

However, the output is this:

line 1
line 2
line 4
line 6

In other words, lline 3 and 5 are disappearing. Why is this happening? I know there are a ton of questions like these on the internet but I haven't seen one that explains why this is happening and how to fix it. I tried replacing <br> with \r\n but it makes no difference.

nived
  • 141
  • 2
  • 11

1 Answers1

0

I works fine for me in text area ...

<?php $html = 'line 1<br>line 2<br><br>line 4<br><br>line 6'; ?>
<textarea cols='60' rows='8'><?php echo preg_replace('#<br\s*/?>#i', "\n", $html); ?></textarea>

Outputs:

textarea output

Scotty G
  • 374
  • 2
  • 6