I want remove some div with id or class which contain words comment
or share
(like:<div id="comment">
, <div class="header-comment">
, <div id="comment-footer">
, <div class="social-share">
), something I use
preg_replace('/<div[^>]*(comment|share)[^>]*>(.*?)<\/div>/is', '', $htmls);
Not work. How to do a right regex? Here is some test code, I want to remove comment
part and keep content
and footer
,
$htmls = <<<EOT
<div id="content">
Main content.
</div>
<div id="comment">
<ul>
<li class="comment">
<div class="header-comment">
Comment:
<span class="date-comment">8/11/2012, 21:25</span>
</div>
<h4>Some Text</h4>
<p class="test-comment">Blah~~ Blah~~ Blah~~</p>
<div class="share">
<div class="vote">
<a class="vota yes" title="Like">2</a>
<a class="vota no" title="Unlike">0</a>
</div>
</div>
</li>
<li class="comment">
<div class="header-comment">
Comment:
<span class="date-comment">8/11/2012, 23:08</span>
</div>
<h4>Other Text</h4>
<p class="test-comment">Blah~~ Blah~~ Blah~~</p>
<div class="share">
<div class="vote">
<a class="vota yes" title="Like">4</a>
<a class="vota no" title="Unlike">0</a>
</div>
</div>
</li>
</ul>
</div>
<div id="footer">
Footer content.
</div>
EOT;
$htmls = preg_replace('/<div[^>]*(comment|share)[^>]*>(.*?)<\/div>/is', '', $htmls);
echo $htmls;