How to replace all XHTML/HTML line breaks (
) with new lines?

前端 未结 4 1259
死守一世寂寞
死守一世寂寞 2020-11-30 04:50

I am looking for the best br2nl function. I would like to replace all instances of
and

4条回答
  •  庸人自扰
    2020-11-30 05:10

    You should be using PHP_EOL constant to have platform independent newlines.

    In my opinion, using non-regexp functions whenever possible makes the code more readable.

    $newlineTags = array(
      '
    ', '
    ', '
    ', ); $html = str_replace($newlineTags, PHP_EOL, $html);

    I am aware this solution has some flaws, but wanted to share my insights still.

提交回复
热议问题