# 如何替換插件的Div內容

"0 - String could not be parsed as XML"


$buffer = preg_replace('<div class="ClassNeedstoReplace">([^]*?)<\/div>/','my custom content',$buffer);


Now in Vm3 I'm using following codes.

$docs = new DOMDocument(); libxml_use_internal_errors(true);$docs->resolveExternals = true;
$docs->loadHTML($buffer);
if($getRelatedProduct != '')$element = $docs->createElement('div',$getRelatedProduct);
$xpath = new DOMXPath($docs);
$query = '//div[@class="'.$class_name.'"]';
$entries =$xpath->query($query); foreach ($entries as $entry) {$entry->parentNode->replaceChild($element,$entry);
}
$docs->recover = true; libxml_clear_errors(); JResponse::setBody(htmlspecialchars_decode($docs->saveHTML()));


bcoz all the instance of the class needs to be replaced.

I know for testing the plugin required another Extension (VM3).its difficult for debuggers.But simply my requirement is simply replace all the class instance with mine.

is there any way to replace Div inside Div structure without breaking layouts using preg_replace ??

The Div Structure is

<div class="product-fields">
<div class="product-field product-field-type-R">
Related Products

Test Product 1Custom prototype for related products            </div>
</div>


I'm trying to replace "product-field product-field-type-R" it may comes more than one inside "product-fields`"

Hope someone will be able to figure out something :)