0

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?

2 Answers 2

4

($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";
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

I am not sure can ask at here, What is PHP Simple HTML Dom?, you got any good link for review it.
@CheongBC It's an html parser for php
As in the manual shown the syntax is correct: $ret = $html->find('.foo');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.