Zelan erabili adierazpen erregularrak (regex) php-n, adibidez:
“div” tag-a “class” atributo barruen “ui-sortable” balidxue dakona:
XML sarrera ($content aldagaidxen edukidxe):
567662
destacado
destacado: Home Actualidad ES
eta hau gudu lortu:
567662
destacado
destacado: Home Actualidad ES
beraz kendu biher diez:
- class=”empty” dakoien “div”-ek
- class=”close” dakoien “div”-ek
- style atributue dakoien “div”-ek
- “ui-sortable” balidxue dakoien “div”-ek “class” atributuen barruen:
PHP kodie:
$content = "".$_POST['content']." "; $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadXML($content); $dom->encoding = 'utf-8'; $xpath = new DOMXPath($dom); $xpath->registerNamespace('php', 'http://php.net/xpath'); $xpath->registerPhpFunctions('preg_match'); $element_remove = $xpath->query('//div[@class="empty" or @class="close"]'); foreach($element_remove as $er) $er->parentNode->removeChild($er); $element_remove = $xpath->query('//div[@style != ""]'); foreach($element_remove as $er) $er->removeAttribute('style'); $element_remove = $xpath->query("//div[php:functionString('preg_match', '/\ ui-sortable/', @class)> 0]"); foreach($element_remove as $er) { $attribute = $er->getAttribute('class'); $attribute = preg_replace('/\ ui-sortable/', '', $attribute); $er->removeAttribute('class'); $er->setAttribute('class', $attribute); } print_r($dom->saveXML());