Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display a DOMElement?

Tags:

html

dom

php

I'm using readability's code to extract HTML from a web page. How do I display it on a page?

$content = grabArticle($webpage);
echo $content;

ERROR => Object of class DOMElement could not be converted to string...
like image 923
HyderA Avatar asked May 12 '10 12:05

HyderA


People also ask

How do I access DOM element?

The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.

How do we get the DOM object in JavaScript?

The HTML DOM can be accessed with JavaScript (and with other programming languages). In the DOM, all HTML elements are defined as objects. The programming interface is the properties and methods of each object. A property is a value that you can get or set (like changing the content of an HTML element).

What is a DOM element?

Document object model. The DOM is the way Javascript sees its containing pages' data. It is an object that includes how the HTML/XHTML/XML is formatted, as well as the browser state. A DOM element is something like a DIV, HTML, BODY element on a page.

Does display none Remove from DOM?

With display:none, it is effectively removed from the DOM. Hiding DOM elements with CSS is a common task. Some wonder whether they should use visibility:hidden or display:none.


1 Answers

Marc B's answer got me on the right track, but I had a similar need and this was the code I landed on:

$newdoc = new DOMDocument;
$node = $newdoc->importNode($node, true);
$newdoc->appendChild($node);
$html = $newdoc->saveHTML();
like image 77
Mike Brittain Avatar answered Sep 30 '22 11:09

Mike Brittain