PHP simple DOM parser confusion, help echo the tags: <div>content code</div>
I'm confuse on what i'm working with.开发者_StackOverflow I'm trying to echo each open upto close tags for <div>
to </div>
using Simple HTMl DOM parser. Using this example given from: (http://simplehtmldom.sourceforge.net/manual.htm), will just try to echo the text area inside the major div tags.
// Find all <div> which attribute id=foo
$ret = $html->find('div[id=foo]');
// Find all <div> with the id attribute
$ret = $html->find('div[id]');
What if i want to echo including the <div>
with and its id, the text or whatsoever code inside it and also echo the close tag </div>
so that I will identify where the code ends.
As shown in the documentation for simplehtmldom for "How to access the HTML element's attributes?" on Tab "Magic attributes":
// Example
$html = str_get_html("<div>foo <b>bar</b></div>");
$e = $html->find("div", 0);
echo $e->tag; // Returns: " div"
echo $e->outertext; // Returns: " <div>foo <b>bar</b></div>"
echo $e->innertext; // Returns: " foo <b>bar</b>"
echo $e->plaintext; // Returns: " foo bar"
Attribute Name Usage
$e->tag Read or write the tag name of element.
$e->outertext Read or write the outer HTML text of element.
$e->innertext Read or write the inner HTML text of element.
$e->plaintext Read or write the plain text of element.
精彩评论