I'm trying to remove a HTML element from a string,
I have the following preg_replace
;
$body = preg_replace('#<div class="code-block code-block-12" style="margin: 8px 0; clear: both;">(.*?)</div>#', '', $body);
But the preg_replace
doesn't seem to work;
Here is the full code;
$html = new DOMDocument();
@$html->loadHtmlFile($url);
$xpath = new DOMXPath( $html );
$nodelist = $xpath->query( '//*[@class="coincodex-content"]' );
$body = '';
foreach ($nodelist as $n){
$body .= $html->saveHtml($n)."\n";
}
$body = preg_replace('#<div class="code-block code-block-12" style="margin: 8px 0; clear: both;">(.*?)</div>#', '', $body);
The current output is this;
<div class="coincodex-content">
hello this is content
<div class="code-block code-block-12" style="margin: 8px 0; clear: both;">
<div><center><span style="font-size:11px; color: gray;"TEST</span></center>
<b>TEST</b><br><br></div></div>
<div class="rp4wp-related-posts rp4wp-related-post">
</ul></div><!-- AI CONTENT END 1 -->
<div class="entry-tags" style="margin-bottom:15px; font-weight: bold; text-align:center;">Tags: <a href="#" rel="tag">test</a> <a href="#" rel="tag">#tag</a></div>
</div>
And my desired output is ;
<div class="coincodex-content">
hello this is content
</div>
I really appreciate any help I'm sure there is an easier way to achieve this I'm just not entirely sure why my current method is not working thankyou.