Use DomDocument to replace divs with certain class with variables

alutosutm

New Member
I am working on a new PHP CMS system and I want to parse uploaded html templates and modify. I want to take all the DIVs with a class of "editarea", strip out the inner content/html, replace with a variable, and save the stripped out content in another set of variables. The trick is there may be multiple div areas with these classes and there may be other classes with "editarea" such as I started out experimenting with DOMDocument but I am having problems when there are multiple classes separated with spaces:\[code\]<div class="editarea" ><p>Content to pull out and save</p></div><div class="other-class editarea" ><p>Content to pull out and save</p></div>\[/code\]php:\[code\]function set_template($data){$xml=new DOMDocument();$xml->loadHtml($data);$xpath = new DOMXPath($xml);$html = '';foreach($xpath->query('//div[@class="editarea"]/*') as $node) { $html[]= $xml->saveXML($node);}return $html;}\[/code\]The other problem is looping this fuction replacing the data with variable and not loosing the content.
 
Back
Top