php - Use simple dom parser to find an element by a specific attribute? -
i have simple dom parser working, can't find documentation or examples element specific value of attribute.
i have several tables on 1 page, 1 has these attributes these specific values
<table cellpadding="2" cellspacing="1" bgcolor="#a0a0a0">
how can echo whole entire html table these values.
what have:
<?php include('simple_html_dom.php'); $url = htmlspecialchars($_get["newurl"]); $html = file_get_html ( $url ); echo $url; foreach ( $html->find ( 'table' ) $element ) { echo $element . php_eol; flush (); } ?>
are lazy enough read manual
look magic attributes
section
// 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"
so in code, can use echo $element->outertext;
change code to
<?php if ( $table = $html->find( "table" ) ) { foreach( $table $element ) { echo $element->outertext.php_eol; } } ?>
Comments
Post a Comment