This commit is contained in:
steven 2025-08-11 22:23:30 +02:00
commit 72a26edcff
22092 changed files with 2101903 additions and 0 deletions

View file

@ -0,0 +1,11 @@
# __construct
```php
__construct ( [ object $dom ] ) : object
```
| Parameter | Description
| --------- | -----------
| `dom` | An object of type [`simple_html_dom`](api/simple_html_dom/).
Constructs a new object of type `simple_html_dom_node`, assignes `$dom` as DOM object and adds itself to the list of nodes in `$dom`.

View file

@ -0,0 +1,7 @@
# __destruct
```php
__destruct ( )
```
Destructs the current object and frees memory.

View file

@ -0,0 +1,22 @@
# __get
```php
__get ( string $name ) : mixed
```
| Parameter | Description
| --------- | -----------
| `name` | `outertext`, `innertext`, `plaintext`, `xmltext` or attribute name.
See [magic methods](http://php.net/manual/en/language.oop5.overloading.php#object.get)
If the provided name is a valid attribute name, returns the attribute value. Otherwise a value according to the table below.
| Name | Description
| ---- | -----------
| `outertext` | Returns the outer text of the current node.
| `innertext` | Returns the inner text of the current node.
| `plaintext` | Returns the plain text of the current node.
| `xmltext` | Returns the xml representation for the inner text of the current node as a CDATA section.
Returns nothing if the provided name is neither a valid attribute name, nor a valid parameter name.

View file

@ -0,0 +1,19 @@
# __isset
```php
__isset ( string $name ) : bool
```
| Parameter | Description
| --------- | -----------
| `name` | `outertext`, `innertext`, `plaintext` or attribute name.
See [magic methods](http://php.net/manual/en/language.oop5.overloading.php#object.get)
Returns true if the provided name is a valid attribute name or any of the values in the table below. False otherwise.
| Name | Description
| ---- | -----------
| `outertext` | Returns the outer text of the current node.
| `innertext` | Returns the inner text of the current node.
| `plaintext` | Returns the plain text of the current node.

View file

@ -0,0 +1,18 @@
# __set
```php
__set ( string $name, mixed $value )
```
| Parameter | Description
| --------- | -----------
| `name` | `outertext`, `innertext` or attribute name.
| `value` | Value to set.
See [magic methods](http://php.net/manual/en/language.oop5.overloading.php#object.get)
Sets the outer text of the current node to `$value` if `$name` is `outertext`.
Sets the inner text of the current node to `$value` if `$name` is `innertext`.
Otherwise, adds or updates an attribute with name `$name` and value `$value` to the current node.

View file

@ -0,0 +1,7 @@
# __toString
```php
__toString ( ) : string
```
Returns the outer text of the current node.

View file

@ -0,0 +1,7 @@
# __unset
```php
__unset ( string $name )
```
Removes the attribute with name `$name` from the current node if it exists.

View file

@ -0,0 +1,23 @@
# addClass
```php
addClass ( mixed $class )
```
| Parameter | Description
| --------- | -----------
| `class` | Specifies one or more class names to be added.
Adds one or more class names to the current node.
**Remarks**
* To add more than one class, separate the class names with space or provide them as an array.
**Examples**
```php
$node->addClass('hidden');
$node->addClass('article important');
$node->addClass(array('article', 'new'));
```

View file

@ -0,0 +1,13 @@
# appendChild
```php
appendChild ( object $node ) : object
```
| Parameter | Description
| --------- | -----------
| `node` | An object of type [`simple_html_dom_node`](../simple_html_dom_node/)
Makes the current node parent of the node provided to this function.
Returns the provided node.

View file

@ -0,0 +1,15 @@
# childNodes
```php
childNodes ( [ int $idx = -1 ] ) : mixed
```
| Parameter | Description
| --------- | -----------
| `idx` | Index of the node to return or `-1` to return all nodes.
Returns all or one specific child node from the current node.
## Remarks
This function is a wrapper for [`children`](../children/)

View file

@ -0,0 +1,11 @@
# children
```php
children ( [ int $idx = -1 ] ) : mixed
```
| Parameter | Description
| --------- | -----------
| `idx` | Index of the node to return or `-1` to return all nodes.
Returns all or one specific child node from the current node.

View file

@ -0,0 +1,7 @@
# clear
```php
clear ( )
```
Sets all properties in the current node, which contain objects, to null.

View file

@ -0,0 +1,13 @@
# convert_text
```php
convert_text ( string $text ) : string
```
| Parameter | Description
| --------- | -----------
| `text` | Text to convert.
Assumes that the provided text is in the form of the configured source character set (see [`sourceCharset`](../simple_html_dom_node/) and converts it to the specified target character set (see [`targetCharset`](../simple_html_dom_node/)).
Returns the converted text.

View file

@ -0,0 +1,12 @@
# dump
```php
dump ( [ bool $show_attr = false [, int $depth = 0 ]] )
```
| Parameter | Description
| --------- | -----------
| `show_attr` | Attribute names are included in the output if enabled.
| `depth` | Depth of the current element
Dumps information about the current node and all child nodes recursively.

View file

@ -0,0 +1,11 @@
# dump_node
```php
dump_node ( [ bool $echo = true ] ) : mixed
```
| Parameter | Description
| --------- | -----------
| `echo` | Echoes the dump details directly if enabled.
Dumps information about the current document node. Returns a string if `$echo` is set to false, null otherwise.

View file

@ -0,0 +1,44 @@
# find
```php
find (
string $selector
[, int $idx = null ]
[, bool $lowercase = false ]
) : mixed
```
| Parameter | Description
| --------- | -----------
| `selector` | [CSS](https://www.w3.org/TR/selectors/) selector.
| `idx` | Index of element to return.
| `lowercase` | Matches tag names case insensitive (lowercase) if enabled.
Finds one or more nodes in the current document, using CSS selectors.
* Returns null if no match was found.
* Returns an array of [`simple_html_dom_node`](../simple_html_dom_node/) if `$idx` is null.
* Returns an object of type [`simple_html_dom_node`](../simple_html_dom_node/) if `$idx` is anything __but__ null.
## Supported Selectors
| Selector | Description
| --------- | -----------
| `*` | [Universal selector](https://www.w3.org/TR/selectors/#the-universal-selector)
| `E` | [Type (tag name) selector](https://www.w3.org/TR/selectors/#type-selectors)
| `E#id` | [ID selector](https://www.w3.org/TR/selectors/#id-selectors)
| `E.class` | [Class selector](https://www.w3.org/TR/selectors/#class-html)
| `E[attr]` | [Attribute selector](https://www.w3.org/TR/selectors/#attribute-selectors)
| `E[attr="value"]` | [Attribute selector](https://www.w3.org/TR/selectors/#attribute-selectors)
| `E[attr="value"] i` | [Case-sensitivity](https://www.w3.org/TR/selectors/#attribute-case)
| `E[attr="value"] s` | [Case-sensitivity](https://www.w3.org/TR/selectors/#attribute-case)
| `E[attr~="value"]` | [Attribute selector](https://www.w3.org/TR/selectors/#attribute-selectors)
| `E[attr^="value"]` | [Substring matching attribute selector](https://www.w3.org/TR/selectors/#attribute-substrings)
| `E[attr$="value"]` | [Substring matching attribute selector](https://www.w3.org/TR/selectors/#attribute-substrings)
| `E[attr*="value"]` | [Substring matching attribute selector](https://www.w3.org/TR/selectors/#attribute-substrings)
| `E[attr|="value"]` | [Attribute selector](https://www.w3.org/TR/selectors/#attribute-selectors)
| `E F` | [Descendant combinator](https://www.w3.org/TR/selectors/#descendant-combinators)
| `E > F` | [Child combinator](https://www.w3.org/TR/selectors/#child-combinators)
| `E + F` | [Next-sibling combinator](https://www.w3.org/TR/selectors/#adjacent-sibling-combinators)
| `E ~ F` | [Subsequent-sibling combinator](https://www.w3.org/TR/selectors/#general-sibling-combinators)
| `E, F` | [Selector list](https://www.w3.org/TR/selectors/#selector-list)

View file

@ -0,0 +1,11 @@
# find_ancestor_tag
```php
find_ancestor_tag ( string $tag ) : object
```
| Parameter | Description
| --------- | -----------
| `tag` | Tag name of the element to find.
Returns the first matching node that matches the specified tag name or null if no match was found.

View file

@ -0,0 +1,7 @@
# firstChild
```php
firstChild ( ) : mixed
```
This function is a wrapper for [`first_child`](../first_child/)

View file

@ -0,0 +1,7 @@
# first_child
```php
first_child ( ) : mixed
```
Returns the first child node of the current node or null if the current nod has no child nodes.

View file

@ -0,0 +1,7 @@
# getAllAttributes
```php
getAllAttributes ( ) : array
```
Returns all attributes for the current node.

View file

@ -0,0 +1,11 @@
# getAttribute
```php
getAttribute ( string $name ) : mixed
```
| Parameter | Description
| --------- | -----------
| `name` | Attribute name.
Returns the value for the attribute `$name`.

View file

@ -0,0 +1,11 @@
# getElementById
```php
getElementById ( string $id ) : object
```
| Parameter | Description
| --------- | -----------
| `id` | Element id.
Returns the first element with the specified id.

View file

@ -0,0 +1,11 @@
# getElementByTagName
```php
getElementByTagName ( string $name ) : object
```
| Parameter | Description
| --------- | -----------
| `name` | Tag name.
Returns the first element with the specified tag name.

View file

@ -0,0 +1,12 @@
# getElementsById
```php
getElementsById ( string $id [, int $idx = null] ) : mixed
```
| Parameter | Description
| --------- | -----------
| `id` | Element id.
| `idx` | Index of element to return.
Returns all elements with the specified id if `$idx` is null, or a specific one if `$idx` is a valid index.

View file

@ -0,0 +1,12 @@
# getElementsByTagName
```php
getElementsByTagName ( string $name [, int $idx = null ] ) : mixed
```
| Parameter | Description
| --------- | -----------
| `name` | Tag name.
| `idx` | Index of the element to return.
Returns all elements with the specified tag name if `$idx` is null, or a specific one if `$idx` is a valid index.

View file

@ -0,0 +1,9 @@
# get_display_size
```php
get_display_size ( ) : mixed
```
Returns false if the current node is not an image.
Returns an associative array of two elements - `height` and `width` - that represent the display size of the image.

View file

@ -0,0 +1,11 @@
# hasAttribute
```php
hasAttribute ( string $name ) : bool
```
| Parameter | Description
| --------- | -----------
| `name` | Name of the attribute.
Returns true if the current node has an attribute with the specified name.

View file

@ -0,0 +1,7 @@
# hasChildNodes
```php
hasChildNodes ( ) : bool
```
This is a wrapper function for [`has_child`](../has_child/).

View file

@ -0,0 +1,17 @@
# hasClass
```php
hasClass ( string $class ) : bool
```
| Parameter | Description
| --------- | -----------
| `class` | Specifies the class name to search for.
Returns true if the current node has the specified class name.
**Examples**
```php
$node->hasClass('article');
```

View file

@ -0,0 +1,7 @@
# has_child
```php
has_child ( ) : bool
```
Returns true if the current node has one or more child nodes.

View file

@ -0,0 +1,7 @@
# innertext
```php
innertext ( ) : string
```
Returns the inner text (everything inside the opening and closing tags) of the current node.

View file

@ -0,0 +1,11 @@
# is_utf8 (static)
```php
is_utf8 ( string $str ) : bool
```
| Parameter | Description
| --------- | -----------
| `str` | String to test.
Returns true if the provided string is a valid UTF-8 string.

View file

@ -0,0 +1,7 @@
# lastChild
```php
lastChild ( ) : object
```
This is a wrapper for [`last_child`](../last_child/).

View file

@ -0,0 +1,7 @@
# last_child
```php
last_child ( ) : object
```
Returns the last child of the current node or null if the current node has no child elements.

View file

@ -0,0 +1,7 @@
# makeup
```php
makeup ( ) : string
```
Returns the HTML representation of the current node.

View file

@ -0,0 +1,19 @@
# match (protected)
```php
match (
string $exp
, string $pattern
, string $value
, string $case_sensitivity
) : bool
```
| Parameter | Description
| --------- | -----------
| `exp` | Expression
| `pattern` | Pattern
| `value` | Value
| `case_sensitivity` | Case sensitivity
Matches a single attribute value against the specified attribute selector. See also [`find`](../find/).

View file

@ -0,0 +1,7 @@
# nextSibling
```php
nextSibling ( ) : object
```
This is a wrapper for [`next_sibling`](../next_sibling/).

View file

@ -0,0 +1,7 @@
# next_sibling
```php
next_sibling ( ) : object
```
Returns the next sibling of the current node or null if the current node has no next sibling.

View file

@ -0,0 +1,7 @@
# nodeName
```php
nodeName ( ) : string
```
Returns the name of the current node (tag name).

View file

@ -0,0 +1,7 @@
# outertext
```php
outertext ( ) : string
```
Returns the outer text (everything including the opening and closing tags) of the current node.

View file

@ -0,0 +1,12 @@
# parent
```php
parent ( [ object $parent = null ] ) : object
```
| Parameter | Description
| --------- | -----------
| `parent` | The parent node
* Returns the parent node of the current node if `$parent` is null.
* Sets the parent node of the current node if `$parent` is not null. In this case the current node is automatically added to the list of nodes in the parent node.

View file

@ -0,0 +1,7 @@
# parentNode
```php
parentNode () : object
```
Returns the current's node parent.

View file

@ -0,0 +1,11 @@
# parse_selector (protected)
```php
parse_selector ( string $selector_string ) : array
```
| Parameter | Description
| --------- | -----------
| `selector_string` | The selector string
Parses a CSS selector into an internal format for further use. See also [`find`](../find/).

View file

@ -0,0 +1,7 @@
# prevSibling
```php
prevSibling ( ) : object
```
This is a wrapper for [`previous_sibling`](../previous_sibling/).

View file

@ -0,0 +1,7 @@
# prev_sibling
```php
prev_sibling ( ) : object
```
Returns the previous sibling of the current node, or null if the current node has no previous sibling.

View file

@ -0,0 +1,39 @@
# remove
```php
remove ( )
```
Removes the current node recursively from the DOM.
Does nothing if the node has no parent (root node);
**Example**
```php
$html = str_get_html(<<<EOD
<html>
<body>
<table>
<tr><th>Title</th></tr>
<tr><td>Row 1</td></tr>
</table>
</body>
</html>
EOD
);
$table = $html->find('table', 0);
$table->remove();
echo $html;
/**
* Returns
*
* <html> <body> </body> </html>
*/
```
**Remarks**
* Whitespace immediately **before** the removed node will remain in the DOM.

View file

@ -0,0 +1,11 @@
# removeAttribute
```php
removeAttribute ( string $name )
```
| Parameter | Description
| --------- | -----------
| `name` | Name of the attribute to remove.
Removes the attribute with the speicified name from the current node.

View file

@ -0,0 +1,43 @@
# removeChild
```php
removeChild ( object $node )
```
| Parameter | Description
| --------- | -----------
| `node` | Node to remove from current element, must be a child of the current element.
Removes the node recursively from the DOM.
Does nothing if the provided node is not a child of the current node.
**Example**
```php
$html = str_get_html(<<<EOD
<html>
<body>
<table>
<tr><th>Title</th></tr>
<tr><td>Row 1</td></tr>
</table>
</body>
</html>
EOD
);
$body = $html->find('body', 0);
$body->removeChild($body->find('table', 0));
echo $html;
/**
* Returns
*
* <html> <body> </body> </html>
*/
```
**Remarks**
* Whitespace immediately **before** the removed node will remain in the DOM.

View file

@ -0,0 +1,25 @@
# removeClass
```php
removeClass ( [ mixed $class = null ] )
```
| Parameter | Description
| --------- | -----------
| `class` | Specifies one or more class names to be removed.
Removes one or more class names from the current node.
**Remarks**
* To remove more than one class, separate the class names with space or provide them as an array.
* If no parameter is specified, this method will remove all class names from the current node.
**Examples**
```php
$node->removeClass('hidden');
$node->removeClass('article important');
$node->removeClass(array('article', 'new'));
$node->removeClass();
```

View file

@ -0,0 +1,20 @@
# save
```php
save ( [ string $filepath = '' ] ) : string
```
Writes the current node to file.
| Parameter | Description
| --------- | -----------
| `filepath` | Writes to file if the provided file path is not empty.
Returns the document string.
**Examples**
```php
$string = $node->save();
$string = $node->save($file);
```

View file

@ -0,0 +1,19 @@
# seek (protected)
```php
seek (
string $selector
, array &$ret
, string $parent_cmd
[, bool $lowercase = false ]
)
```
| Parameter | Description
| --------- | -----------
| `selector` | The current selector.
| `ret` | Previous return value (starting point).
| `parent_cmd` | The combinator used before the current selector.
| `lowercase` | Matches tag names case insensitive (lowercase) if enabled.
Starts by searching for child elements of `$ret` that match the specified selector. Adds matching elements to `$ret` (for the next iteration).

View file

@ -0,0 +1,12 @@
# setAttribute
```php
setAttribute ( string $name, string $value )
```
| Parameter | Description
| --------- | -----------
| `name` | Attribute name
| `value` | Attribute value
Adds or sets an attribute in the current node to the specified value.

View file

@ -0,0 +1,30 @@
---
title: simple_html_dom_node
---
# simple_html_dom_node
Represents a single node in the DOM tree (see [`simple_html_dom`](../../simple_html_dom/simple_html_dom/)).
# Public Properties
| Property | Description
| -------- | -----------
| `_` | Node meta data (i.e. type of node).
| `attr` | List of attributes.
| `children` | List of child nodes.
| `nodes` | List of nodes.
| `nodetype` | Node type.
| `parent` | Parent node object.
| `tag` | Node's tag name.
| `tag_start` | Start position of the tag name in the original document.
# Protected Properties
None.
# Private Properties
| Property | Description
| -------- | -----------
| `dom` | The DOM object (see [`simple_html_dom`](../../simple_html_dom/simple_html_dom/)).

View file

@ -0,0 +1,7 @@
# text
```php
text ( ) : string
```
Returns the (HTML) text representation for the current node recursively.

View file

@ -0,0 +1,7 @@
# xmltext
```php
xmltext ( ) : string
```
Returns the xml representation for the inner text of the current node as a CDATA section.