PHP Class PHPHtmlParser\Dom

显示文件 Open project: paquettg/php-html-parser Class Usage Examples

Public Properties

Property Type Description
$root PHPHtmlParser\Dom\HtmlNode Contains the root node of this dom tree.

Protected Properties

Property Type Description
$content Content The document string.
$defaultCharset string The charset we would like the output to be in.
$globalOptions array A global options array to be used by all load calls.
$options Options A persistent option object to be used for all options in the parsing of the file.
$raw string The raw version of the document string.
$rawSize integer The original file size of the document.
$selfClosing array A list of tags which will always be self closing
$size integer The size of the document after it is cleaned.

Public Methods

Method Description
__get ( string $name ) : mixed A simple wrapper around the root node.
__toString ( ) : string Returns the inner html of the root node.
addSelfClosingTag ( string | array $tag ) Adds the tag (or tags in an array) to the list of tags that will always be self closing.
clearSelfClosingTags ( ) Sets the list of self closing tags to empty.
find ( string $selector, integer $nth = null ) : array Find elements by css selector on the root node.
firstChild ( ) : AbstractNode Simple wrapper function that returns the first child.
getElementById ( string $id ) : AbstractNode Simple wrapper function that returns an element by the id.
getElementsByClass ( string $class ) : array Simple wrapper function that returns all elements by class name.
getElementsByTag ( string $name ) : array Simple wrapper function that returns all elements by tag name.
lastChild ( ) : AbstractNode Simple wrapper function that returns the last child.
load ( string $str, array $options = [] ) Attempts to load the dom from any resource, string, file, or URL.
loadFromFile ( string $file, array $options = [] ) Loads the dom from a document file/url
loadFromUrl ( string $url, array $options = [], phphtmlparser\CurlInterface $curl = null ) Use a curl interface implementation to attempt to load the content from a url.
loadStr ( string $str, array $option ) Parsers the html of the given string. Used for load(), loadFromFile(), and loadFromUrl().
removeSelfClosingTag ( string | array $tag ) Removes the tag (or tags in an array) from the list of tags that will always be self closing.
setOptions ( array $options ) Sets a global options array to be used by all load calls.

Protected Methods

Method Description
clean ( string $str ) : string Cleans the html of any none-html information.
detectCharset ( ) : boolean Attempts to detect the charset that the html was sent in.
isLoaded ( ) Checks if the load methods have been called.
parse ( ) Attempts to parse the html in content.
parseTag ( ) : array Attempt to parse a tag out of the content.

Method Details

__get() public method

A simple wrapper around the root node.
public __get ( string $name ) : mixed
$name string
return mixed

__toString() public method

Returns the inner html of the root node.
public __toString ( ) : string
return string

addSelfClosingTag() public method

Adds the tag (or tags in an array) to the list of tags that will always be self closing.
public addSelfClosingTag ( string | array $tag )
$tag string | array

clean() protected method

Cleans the html of any none-html information.
protected clean ( string $str ) : string
$str string
return string

clearSelfClosingTags() public method

Sets the list of self closing tags to empty.

detectCharset() protected method

Attempts to detect the charset that the html was sent in.
protected detectCharset ( ) : boolean
return boolean

find() public method

Find elements by css selector on the root node.
public find ( string $selector, integer $nth = null ) : array
$selector string
$nth integer
return array

firstChild() public method

Simple wrapper function that returns the first child.
public firstChild ( ) : AbstractNode
return PHPHtmlParser\Dom\AbstractNode

getElementById() public method

Simple wrapper function that returns an element by the id.
public getElementById ( string $id ) : AbstractNode
$id string
return PHPHtmlParser\Dom\AbstractNode

getElementsByClass() public method

Simple wrapper function that returns all elements by class name.
public getElementsByClass ( string $class ) : array
$class string
return array

getElementsByTag() public method

Simple wrapper function that returns all elements by tag name.
public getElementsByTag ( string $name ) : array
$name string
return array

isLoaded() protected method

Checks if the load methods have been called.
protected isLoaded ( )

lastChild() public method

Simple wrapper function that returns the last child.
public lastChild ( ) : AbstractNode
return PHPHtmlParser\Dom\AbstractNode

load() public method

Attempts to load the dom from any resource, string, file, or URL.
public load ( string $str, array $options = [] )
$str string
$options array

loadFromFile() public method

Loads the dom from a document file/url
public loadFromFile ( string $file, array $options = [] )
$file string
$options array

loadFromUrl() public method

Use a curl interface implementation to attempt to load the content from a url.
public loadFromUrl ( string $url, array $options = [], phphtmlparser\CurlInterface $curl = null )
$url string
$options array
$curl phphtmlparser\CurlInterface

loadStr() public method

Parsers the html of the given string. Used for load(), loadFromFile(), and loadFromUrl().
public loadStr ( string $str, array $option )
$str string
$option array

parse() protected method

Attempts to parse the html in content.
protected parse ( )

parseTag() protected method

Attempt to parse a tag out of the content.
protected parseTag ( ) : array
return array

removeSelfClosingTag() public method

Removes the tag (or tags in an array) from the list of tags that will always be self closing.
public removeSelfClosingTag ( string | array $tag )
$tag string | array

setOptions() public method

Sets a global options array to be used by all load calls.
public setOptions ( array $options )
$options array

Property Details

$content protected_oe property

The document string.
protected Content,phphtmlparser $content
return Content

$defaultCharset protected_oe property

The charset we would like the output to be in.
protected string $defaultCharset
return string

$globalOptions protected_oe property

A global options array to be used by all load calls.
protected array $globalOptions
return array

$options protected_oe property

A persistent option object to be used for all options in the parsing of the file.
protected Options,phphtmlparser $options
return Options

$raw protected_oe property

The raw version of the document string.
protected string $raw
return string

$rawSize protected_oe property

The original file size of the document.
protected int $rawSize
return integer

$root public_oe property

Contains the root node of this dom tree.
public HtmlNode,PHPHtmlParser\Dom $root
return PHPHtmlParser\Dom\HtmlNode

$selfClosing protected_oe property

A list of tags which will always be self closing
protected array $selfClosing
return array

$size protected_oe property

The size of the document after it is cleaned.
protected int $size
return integer