PHP Simple HTML DOM Parser: API Reference in simplehtmldom API 6
Same filename and directory in other branches
Index
API Reference
Top Helper functions
DOM methods & properties
Element methods & properties
DOM traversing
Name | Description |
---|---|
object str_get_html ( string $content ) | Creates a DOM object from a string. |
object file_get_html ( string $filename ) | Creates a DOM object from a file or a URL. |
DOM methods & properties
Name | Description |
---|---|
void
__construct ( [string $filename] ) |
Constructor, set the filename parameter will automatically load the contents, either text or file/url. |
string
plaintext |
Returns the contents extracted from HTML. |
void
clear () |
Clean up memory. |
void
load ( string $content ) |
Load contents from a string. |
string
save ( [string $filename] ) |
Dumps the internal DOM tree back into a string. If the $filename is set, result string will save to file. |
void
load_file ( string $filename ) |
Load contents from a from a file or 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 element object if index is set, otherwise return an array of object. |
Element methods & properties
Name | Description |
---|---|
string
[attribute] |
Read or write element's attribure value. |
string
tag |
Read or write the tag name of element. |
string
outertext |
Read or write the outer HTML text of element. |
string
innertext |
Read or write the inner HTML text of element. |
string
plaintext |
Read or write the plain text of element. |
mixed
find ( string $selector [, int $index] ) |
Find children by the CSS selector. Returns the Nth element object if index is set, otherwise, return an array of object. |
DOM traversing
Name | Description |
---|---|
mixed
$e->children ( [int $index] ) |
Returns the Nth child object if index is set, otherwise return an array of children. |
element
$e->parent () |
Returns the parent of element. |
element
$e->first_child () |
Returns the first child of element, or null if not found. |
element
$e->last_child () |
Returns the last child of element, or null if not found. |
element
$e->next_sibling () |
Returns the next sibling of element, or null if not found. |
element
$e->prev_sibling () |
Returns the previous sibling of element, or null if not found. |
Camel naming convertions
TopYou can also call methods with W3C STANDARD camel naming convertions.
Method | Mapping |
---|---|
array
$e->getAllAttributes () |
array
$e->attr |
string
$e->getAttribute ( $name ) |
string
$e->attribute |
void
$e->setAttribute ( $name, $value ) |
void
$value = $e->attribute |
bool
$e->hasAttribute ( $name ) |
bool
isset($e->attribute) |
void
$e->removeAttribute ( $name ) |
void
$e->attribute = null |
element
$e->getElementById ( $id ) |
mixed
$e->find ( "#$id", 0 ) |
mixed
$e->getElementsById ( $id [,$index] ) |
mixed
$e->find ( "#$id" [, int $index] ) |
element
$e->getElementByTagName ($name ) |
mixed
$e->find ( $name, 0 ) |
mixed
$e->getElementsByTagName ( $name [, $index] ) |
mixed
$e->find ( $name [, int $index] ) |
element
$e->parentNode () |
element
$e->parent () |
mixed
$e->childNodes ( [$index] ) |
mixed
$e->children ( [int $index] ) |
element
$e->firstChild () |
element
$e->first_child () |
element
$e->lastChild () |
element
$e->last_child () |
element
$e->nextSibling () |
element
$e->next_sibling () |
element
$e->previousSibling () |
element
$e->prev_sibling () |
Author: S.C. Chen (me578022@gmail.com)
Original idea is from Jose Solorzano's HTML Parser for PHP 4.
Contributions by: Contributions by: Yousuke Kumakura, Vadim Voituk, Antcs
File
simplehtmldom/manual/manual_api.htmView source
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>PHP Simple HTML DOM Parser: API Reference</title> <link href="css/default.css" rel="stylesheet" type="text/css"> </head> <body> <h1><a name="top"></a>PHP Simple HTML DOM Parser Manual</h1> <div id="content"> <h2>Index</h2> <ul> <li><a href="manual.htm">Back</a></li> <li><a href="#api">API Reference</a></li> <li><a href="#camel">Camel naming conventions</a></li> </ul> <a name="api"></a> <h2>API Reference</h2> <a class="top" href="#top">Top</a> <div class="code"> <strong>Helper</strong> functions <table width="100%" cellpadding="1" cellspacing="1"> <tr> <th width="320">Name</th> <th>Description</th> </tr> <tr> <td><span class="returns">object</span> str_get_html ( <span class="var">string $content</span> )</td> <td class="description">Creates a DOM object from a string.</td> </tr> <tr> <td><span class="returns">object</span> file_get_html ( <span class="var">string $filename</span> )</td> <td class="description">Creates a DOM object from a file or a URL.</td> </tr> </table> <br> <strong>DOM</strong> methods & properties <br> <table width="100%" cellpadding="1" cellspacing="1"> <tr> <th width="320"> Name</th> <th> Description</th> </tr> <tr> <td> <div class="returns">void</div> __construct ( <span class="var">[string $filename]</span> )</td> <td class="description">Constructor, set the filename parameter will automatically load the contents, either text or file/url.</td> </tr> <tr> <td> <div class="returns">string</div> plaintext</td> <td class="description">Returns the contents extracted from HTML.</td> </tr> <tr> <td> <div class="returns">void</div> clear ()</td> <td class="description">Clean up memory.</td> </tr> <tr> <td> <div class="returns">void</div> load ( <span class="var">string $content </span>)</td> <td class="description"> Load contents from a <strong>string</strong>. </td> </tr> <tr> <td> <div class="returns">string</div> save ( <span class="var">[string $filename]</span> )</td> <td class="description">Dumps the internal DOM tree back into a <strong>string</strong>. If the $filename is set, result string will save to file. </td> </tr> <tr> <td> <div class="returns">void</div> load_file (<span class="var"> string $filename</span> )</td> <td class="description"> Load contents from a from a file or a URL.</td> </tr> <tr> <td> <div class="returns">void</div> set_callback ( <span class="var">string $function_name </span>)</td> <td class="description">Set a callback function. </td> </tr> <tr> <td> <div class="returns">mixed</div> find (<span class="var"> string $selector [, int $index] </span>)</td> <td class="description">Find elements by the CSS selector. Returns the Nth element <strong>object</strong> if <strong>index</strong> is set, otherwise return an <strong>array</strong> of object. </td> </tr> </table> <br> <strong>Element</strong> methods & properties <br> <table width="100%" cellpadding="1" cellspacing="1"> <tr> <th width="320">Name</th> <th>Description</th> </tr> <tr> <td> <div class="returns">string</div> <span class="var">[attribute]</span></td> <td class="description">Read or write element's attribure value. </td> </tr> <tr> <td> <div class="returns">string</div> tag</td> <td class="description">Read or write the tag name of element.</td> </tr> <tr> <td> <div class="returns">string</div> outertext</td> <td class="description">Read or write the outer HTML text of element.</td> </tr> <tr> <td> <div class="returns">string</div> innertext</td> <td class="description">Read or write the inner HTML text of element.</td> </tr> <tr> <td> <div class="returns">string</div> plaintext</td> <td class="description">Read or write the plain text of element.</td> </tr> <tr> <td> <div class="returns">mixed</div> find (<span class="var"> string $selector [, int $index] </span>)</td> <td class="description">Find children by the CSS selector. Returns the Nth element <strong>object</strong> if <strong>index</strong> is set, otherwise, return an <strong>array</strong> of object. </td> </tr> </table> <strong><br> DOM</strong> traversing<br> <table width="100%" cellpadding="1" cellspacing="1"> <tr> <th width="320">Name</th> <th>Description</th> </tr> <tr> <td> <div class="returns">mixed</div> $e->children ( <span class="var">[int $index]</span> ) </td> <td class="description">Returns the Nth child <strong>object</strong> if <strong>index</strong> is set, otherwise return an <strong>array</strong> of children. </td> </tr> <tr> <td> <div class="returns">element</div> $e->parent () </td> <td class="description">Returns the parent of element. </td> </tr> <tr> <td> <div class="returns">element</div> $e->first_child () </td> <td class="description">Returns the first child of element, or <strong>null</strong> if not found. </td> </tr> <tr> <td> <div class="returns">element</div> $e->last_child () </td> <td class="description">Returns the last child of element, or <strong>null</strong> if not found. </td> </tr> <tr> <td> <div class="returns">element</div> $e->next_sibling () </td> <td class="description">Returns the next sibling of element, or<strong> null</strong> if not found. </td> </tr> <tr> <td> <div class="returns">element</div> $e->prev_sibling () </td> <td class="description">Returns the previous sibling of element, or <strong>null</strong> if not found. </td> </tr> </table> </div> <a name="camel"></a> <h2>Camel naming convertions</h2> <a class="top" href="#top">Top</a> <div class="code">You can also call methods with W3C STANDARD camel naming convertions.<br> <br> <table width="100%" cellpadding="1" cellspacing="1"> <tr> <th width="50%">Method</th> <th>Mapping</th> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">array</div> $e->getAllAttributes () </td> <td> <div class="returns">array</div> $e-><span class="var">attr</span></td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">string</div> $e->getAttribute ( <span class="var">$name</span> ) </td> <td> <div class="returns">string</div> $e-><span class="var">attribute</span></td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">void</div> $e->setAttribute ( <span class="var">$name, $value</span> ) </td> <td> <div class="returns">void</div> $value = $e-><span class="var">attribute</span></td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">bool</div> $e->hasAttribute ( <span class="var">$name</span> ) </td> <td> <div class="returns">bool</div> isset($e-><span class="var">attribute</span>)</td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">void</div> $e->removeAttribute ( <span class="var">$name</span> ) </td> <td> <div class="returns">void</div> $e-><span class="var">attribute</span> = null</td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">element</div> $e->getElementById ( <span class="var">$id</span> ) </td> <td> <div class="returns">mixed</div> $e->find (<span class="var"> "#$id", 0 </span>)</td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">mixed</div> $e->getElementsById ( <span class="var">$id [,$index] </span> ) </td> <td> <div class="returns">mixed</div> $e->find (<span class="var"> "#$id" [, int $index] </span>)</td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">element</div> $e->getElementByTagName (<span class="var">$name</span> ) </td> <td> <div class="returns">mixed</div> $e->find (<span class="var"> $name, 0 </span>)</td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">mixed</div> $e->getElementsByTagName ( <span class="var">$name [, $index]</span> ) </td> <td> <div class="returns">mixed</div> $e->find (<span class="var"> $name [, int $index] </span>)</td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">element</div> $e->parentNode () </td> <td> <div class="returns">element</div> $e->parent () </td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">mixed</div> $e->childNodes ( <span class="var">[$index]</span> ) </td> <td> <div class="returns">mixed</div> $e->children ( <span class="var">[int $index]</span> ) </td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">element</div> $e->firstChild () </td> <td> <div class="returns">element</div> $e->first_child () </td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">element</div> $e->lastChild () </td> <td> <div class="returns">element</div> $e->last_child () </td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">element</div> $e->nextSibling () </td> <td> <div class="returns">element</div> $e->next_sibling () </td> </tr> <tr bgcolor="#EEEEEE"> <td> <div class="returns">element</div> $e->previousSibling () </td> <td> <div class="returns">element</div> $e->prev_sibling () </td> </tr> </table> </div> <div><br> Author: S.C. Chen (me578022@gmail.com)<br> Original idea is from Jose Solorzano's <a href="http://php-html.sourceforge.net/">HTML Parser for PHP 4</a>. <br> Contributions by: Contributions by: Yousuke Kumakura, Vadim Voituk, Antcs<br> </div> </div> </body> </html> <!--$Rev: 165 $-->