Simple html dom last child

simple_html_dom

Represents the DOM in memory. Provides functions to parse documents and access individual elements (see simple_html_dom_node ).

Public Properties

Property Description
root Root node of the document.
nodes List of top-level nodes in the document.
callback Callback function that is called for each element in the DOM when generating outertext.
lowercase If enabled, all tag names are converted to lowercase when parsing documents.
original_size Original document size in bytes.
size Current document size in bytes.
_charset Charset of the original document.
_target_charset Target charset for the current document.
default_span_text Text to return for elements.

Protected Properties

Property Description
pos Current parsing position within doc .
doc The original document.
char Character at position pos in doc .
cursor Current element cursor in the document.
parent Parent element node.
noise Noise from the original document (i.e. scripts, comments, etc. ).
token_blank Tokens that are considered whitespace in HTML.
token_equal Tokens to identify the equal sign for attributes, stopping either at the closing tag («/» i.e. ) or the end of an opening tag («>» i.e. ).
token_slash Tokens to identify the end of a tag name. A tag name either ends on the ending slash («/» i.e. ) or whitespace ( «\s\r\n\t» ).
token_attr Tokens to identify the end of an attribute.
default_br_text Text to return for
elements.
self_closing_tags A list of tag names where the closing tag is omitted.
block_tags A list of tag names where remaining unclosed tags are forcibly closed.
optional_closing_tags A list of tag names where the closing tag can be omitted.
Читайте также:  Python сортировка массива чисел

Источник

Parsing documents

The parser accepts documents in the form of URLs, files and strings. The document must be accessible for reading and cannot exceed MAX_FILE_SIZE .

Name Description
str_get_html( string $content ) : object Creates a DOM object from string.
file_get_html( string $filename ) : object Creates a DOM object from file or URL.

DOM methods & properties

Name Description
__construct( [string $filename] ) : void Constructor, set the filename parameter will automatically load the contents, either text or file/url.
plaintext : string Returns the contents extracted from HTML.
clear() : void Clean up memory.
load( string $content ) : void Load contents from string.
save( [string $filename] ) : string Dumps the internal DOM tree back into a string. If the $filename is set, result string will save to file.
load_file( string $filename ) : void Load contents from a file or a URL.
set_callback( string $function_name ) : void Set a callback function.
find( string $selector [, int $index] ) : mixed 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
[attribute] : string Read or write element’s attribute value.
tag : string Read or write the tag name of element.
outertext : string Read or write the outer HTML text of element.
innertext : string Read or write the inner HTML text of element.
plaintext : string Read or write the plain text of element.
find( string $selector [, int $index] ) : mixed 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
$e->children( [int $index] ) : mixed Returns the Nth child object if index is set, otherwise return an array of children.
$e->parent() : element Returns the parent of element.
$e->first_child() : element Returns the first child of element, or null if not found.
$e->last_child() : element Returns the last child of element, or null if not found.
$e->next_sibling() : element Returns the next sibling of element, or null if not found.
$e->prev_sibling() : element Returns the previous sibling of element, or null if not found.
Читайте также:  Html to wordpress service

Camel naming conventions

Method Mapping
$e->getAllAttributes() $e->attr
$e->getAttribute( $name ) $e->attribute
$e->setAttribute( $name, $value) $value = $e->attribute
$e->hasAttribute( $name ) isset($e->attribute)
$e->removeAttribute ( $name ) $e->attribute = null
$e->getElementById ( $id ) $e->find ( «#$id», 0 )
$e->getElementsById ( $id [,$index] ) $e->find ( «#$id» [, int $index] )
$e->getElementByTagName ($name ) $e->find ( $name, 0 )
$e->getElementsByTagName ( $name [, $index] ) $e->find ( $name [, int $index] )
$e->parentNode () $e->parent ()
$e->childNodes ( [$index] ) $e->children ( [int $index] )
$e->firstChild () $e->first_child ()
$e->lastChild () $e->last_child ()
$e->nextSibling () $e->next_sibling ()
$e->previousSibling () $e->prev_sibling ()

Источник

Parsing documents

The parser accepts documents in the form of URLs, files and strings. The document must be accessible for reading and cannot exceed MAX_FILE_SIZE .

Name Description
str_get_html( string $content ) : object Creates a DOM object from string.
file_get_html( string $filename ) : object Creates a DOM object from file or URL.

DOM methods & properties

Name Description
__construct( [string $filename] ) : void Constructor, set the filename parameter will automatically load the contents, either text or file/url.
plaintext : string Returns the contents extracted from HTML.
clear() : void Clean up memory.
load( string $content ) : void Load contents from string.
save( [string $filename] ) : string Dumps the internal DOM tree back into a string. If the $filename is set, result string will save to file.
load_file( string $filename ) : void Load contents from a file or a URL.
set_callback( string $function_name ) : void Set a callback function.
find( string $selector [, int $index] ) : mixed 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
[attribute] : string Read or write element’s attribute value.
tag : string Read or write the tag name of element.
outertext : string Read or write the outer HTML text of element.
innertext : string Read or write the inner HTML text of element.
plaintext : string Read or write the plain text of element.
find( string $selector [, int $index] ) : mixed Find children by the CSS selector. Returns the Nth element object if index is set, otherwise return an array of object.
Читайте также:  title

DOM traversing

Name Description
$e->children( [int $index] ) : mixed Returns the Nth child object if index is set, otherwise return an array of children.
$e->parent() : element Returns the parent of element.
$e->first_child() : element Returns the first child of element, or null if not found.
$e->last_child() : element Returns the last child of element, or null if not found.
$e->next_sibling() : element Returns the next sibling of element, or null if not found.
$e->prev_sibling() : element Returns the previous sibling of element, or null if not found.

Camel naming conventions

Method Mapping
$e->getAllAttributes() $e->attr
$e->getAttribute( $name ) $e->attribute
$e->setAttribute( $name, $value) $value = $e->attribute
$e->hasAttribute( $name ) isset($e->attribute)
$e->removeAttribute ( $name ) $e->attribute = null
$e->getElementById ( $id ) $e->find ( «#$id», 0 )
$e->getElementsById ( $id [,$index] ) $e->find ( «#$id» [, int $index] )
$e->getElementByTagName ($name ) $e->find ( $name, 0 )
$e->getElementsByTagName ( $name [, $index] ) $e->find ( $name [, int $index] )
$e->parentNode () $e->parent ()
$e->childNodes ( [$index] ) $e->children ( [int $index] )
$e->firstChild () $e->first_child ()
$e->lastChild () $e->last_child ()
$e->nextSibling () $e->next_sibling ()
$e->previousSibling () $e->prev_sibling ()

Источник

How do I find the last <div class> in an HTML File with PHP Simple HTML DOM Parser?

It returns the last child nodes as text, comment or element node (depends on which occurs at last). Solution 1: Well, since returns an holding all the elements, you can fetch the last element with PHP’s regular array functions, e.g. with If SimpleHtmlDom fully implements CSS3 Selectors for querying, you can also modify your query to use to only find the last sibling in returned nodelist.

How do I find the last <div class> in an HTML File with PHP Simple HTML DOM Parser?

// Find all anchors, returns a array of element objects $ret = $html->find('whatever'); 

returns an array holding all the elements, you can fetch the last element with PHP’s regular array functions, e.g. with end

If SimpleHtmlDom fully implements CSS3 Selectors for querying, you can also modify your query to use

to only find the last sibling in returned nodelist.

// Find lastest anchor, returns element object or null if not found (zero based) $ret = $html->find('a', -1); 

lastChild property returns the last child object of an element.

EDIT: not JQuery obviously 🙂 See the W3C selector reference instead: http://www.w3.org/TR/css3-selectors/#last-child-pseudo

JQuery | find() with Examples, The find () is an inbuilt method in jQuery which is used to find all the descendant elements of the selected element. It will traverse all the way down to the last leaf of the selected element in the DOM tree. Here selector is the selected elements of which all the descendant elements are going to be found. …

HTML | DOM lastChild Property

The DOM lastChild property is used to return the last child of the specified node. It returns the last child nodes as text, comment or element node (depends on which occurs at last). It is a read-only property.

Return Value: It returns a node object which represents the last child of the node and null if there are no child elements.

html

Before click on the button:

lastChild

After click on the button:

lasChild

html

Before click on the button:

lastChild

After click on the button:

lasChild

Supported Browsers: The browser supported by lastChild property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 6 and above
  • Firefox 1 and above
  • Opera 12.1 and above
  • Safari 1 and above

What is the DOM? Document Object Model Meaning in, DOM stands for Document Object Model. It is a programming interface that allows us to create, change, or remove elements from the document. We can also add events to these elements to make our page more dynamic. The DOM views an HTML document as a tree of nodes. A node represents an HTML element.

HTML | DOM lastModified Property

The DOM lastModified property in HTML is used to return the date and time of the current document that was last modified. This property is read-only. This property returns a string which contains the date and time when the document was last modified.

Источник

Оцените статью