Remove whitespace from HTML

前端 未结 15 1832
花落未央
花落未央 2020-12-28 14:25

I have HTML code like:

15条回答
  •  忘掉有多难
    2020-12-28 14:34

    I used this regex for me and it works like a charm:

    preg_replace('/[ \t]+(?!="|\')/', '', $html);
    

    These pattern looks for space whitespace and tabulator (at least one), that is not followed by " or '. This is, to avoid removing whitespaces between html attributes.

提交回复
热议问题