Pregunta

I would like to get this code:

<div class="class1">Any Text<div>Or any other Content</div></div>

to this:

<div class="class1 another_class"><div class="extra"></div>Any Text<div>Or any other Content</div></div>

with the PHP Simple HTML Dom Parser

This is my first part:

foreach($html->find(".class1") as $element) {
    $element->class="class1 another_class";
}

But how can I add the "extra"-div?

¿Fue útil?

Solución

($e->innertext)Read or write the inner HTML text of element. may be this gonna work.. :)

foreach($html->find("div.class1") as $element) {
    $element->innertext = '<div class="extra"></div>' . $element->innertext;
    $element->class = "class1 another_class";
}

Otros consejos

The correct syntax is this;

$ret = $html->find('div.foo');
//OR
$ret = $html->find('div[class=foo]');

source: http://simplehtmldom.sourceforge.net/manual.htm
How to find HTML elements? section, tab Advanced

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top