void __construct ( [string $filename] ) Constructor, set the filename parameter will automatically load the contents, either textorfile/url.
string plaintext Returns the contents extracted from HTML.
voidclear () Clean up memory.
voidload ( string $content ) Loadcontentsfrom a string.
stringsave ( [string $filename] ) Dumps the internal DOM tree back into a string. If the $filename isset, resultstring will savetofile.
voidload_file ( string $filename ) Loadcontentsfrom a from a fileor a URL.
void set_callback ( string $function_name ) Set a callback function.
mixed find ( string $selector [, int $index] ) Find elements by the CSS selector. Returns the Nth elementobjectifindexisset, otherwise return an arrayofobject.
find ( string $selector [, int $index] ) // Find all anchors, returns a array of element objects $ret = $html->find('a');
// Find (N)th anchor, returns element object or null if not found (zero based) $ret = $html->find('a', 0);
// Find lastest anchor, returns element object or null if not found (zero based) $ret = $html->find('a', -1);
// Find all <div> with the id attribute $ret = $html->find('div[id]');
// Find all <div> which attribute id=foo $ret = $html->find('div[id=foo]');
// Find all element which id=foo $ret = $html->find('#foo');
// Find all element which class=foo $ret = $html->find('.foo');
// Find all element has attribute id $ret = $html->find('*[id]');
// Find all anchors and images $ret = $html->find('a, img');
// Find all anchors and images with the "title" attribute $ret = $html->find('a[title], img[title]');
// Find all <li> in <ul> $es = $html->find('ul li');
// Find Nested <div> tags $es = $html->find('div div div');
// Find all <td> in <table> which class=hello $es = $html->find('table.hello td');
// Find all td tags with attribite align=center in table tags $es = $html->find(''table td[align=center]');
Element 的方法
1
$e = $html->find("div", 0); //$e 所拥有的方法如下表所示
Attribute Name Usage:
1 2 3 4 5 6 7 8 9 10 11 12
$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. // Example
近期评论