0

I want to get the innerHtml from an element, with simple html dom parser.

For example:

$s = "      <div class="a">
                <p>I don't want this stuff</p>
                <div class="b">
                    <input type="button" value="testing">
                    <p>I want this stuff</p>
                </div>
            </div> ";

$html = str_get_content($s);
$ret = $html->find('div[class=b']);

Now ... I want to initialize another object, but with the html from $ret.

I've tried with $newSource = $ret[0]->save(), but it's not working. In their documentation it doesn't appear something about innerHtml or outerHtml, just innerText.

3 Answers 3

1
$ret[0]->innertext

will give you the inner HTML of the element (even if it's called text, it's actually the whole html)

Sign up to request clarification or add additional context in comments.

Comments

0

According to the documentation there is a way to dump your dom, maybe that can be used as wenn to dump just a part of your some.

echo $ret[0]; // this should return your dom fragment

if you want another object and $object = $ret[0] isn't what you're looking for, this could help:

$html = (string) $ret[0]; // convert to html
$newSource = str_get_content($html); // create new object

Comments

0

Its been a while since I used the class but have you tried echo $ret->plaintext;

1 Comment

it's showing the plaintext, no html. I want to be able to reparse it, and it needs to be html.

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.