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.
`. That's a `
`, newline, `
`. Adjust your regex accordingly... – MonkeyZeus Jun 21 '18 at 18:18
`s or need to replace single ones too? – MonkeyZeus Jun 21 '18 at 18:24