Skip to content

Error when trying to replace a node #73

@ajaybc

Description

@ajaybc

I am trying to replace a node in my DOM with another one. But I am getting the error
"PHP Fatal error: Method PHPHtmlParser\Dom::__toString() must not throw an exception, caught Error: Cannot use object of type PHPHtmlParser\Dom\HtmlNode as array".

Here is the code I am using

$dom = new Dom;
$dom->load('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');
$id = $dom->find('p')[0]->id();
$newChild = new HtmlNode('h1');
$dom->find('p')[0]->getParent()->replaceChild($id, $newChild);
echo $dom;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions