How to remove entire div with preg_replace

前端 未结 4 1374
心在旅途
心在旅途 2021-01-16 17:06

Ok, as it is WordPress problem and it sadly goes a little deeper, I need to remove each representation of parent div and its inside:

4条回答
  •  囚心锁ツ
    2021-01-16 17:50

    .*?<\/div>/s','',$content); ?>
    

    My RegEx is a bit rusty, but I think this should work. Do note that, as others have said, RegEx is not properly equipped to handle some of the complexities of HTML.

    In addition, this pattern won't find embedded div elements with the class sometestclass. You would need recursion for that.

提交回复
热议问题