Regex Remove Images with style tag from Html

后端 未结 5 1195
遥遥无期
遥遥无期 2020-12-11 08:57

I am new to Regex, however I decided it was the easiest route to what I needed to do. Basically I have a string (in PHP) which contains a whole load of HTML code... I want

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 09:08

    Here is another version which works with all tags including ones with spaces between the inline style display:none or display: none. Plus it deletes the content inside the tags.

    $html = preg_replace('/<[^>]+style[^>]+display:\s*none[^>]+>.*?>/', '', $html);
    

    So I have tested it with the following and it works fine.

    Only show
    Delete inside content as well
    this text. Only showDelete inside content as well this text. Only show
    Delete inside content as well
    this text. Only showDelete inside content as well this text.

    Should now only output.

    Only show this text.
    

提交回复
热议问题