PHP Class pQuery\DomNode

Inheritance: implements pquery\IQuery
Show file Open project: tburry/pquery Class Usage Examples

Public Properties

Property Type Description
$attribute_shorttag boolean Use short tags for attributes? If true, then attributes with values equal to the attribute name will not output the value, e.g. selected="selected" will be selected.
$attributes array Attributes of node
$attributes_ns array Namespace info for attributes
$childClass string Name of the class used for {@link addChild()}
$childClass_ASP string Name of the class used for {@link addASP()}
$childClass_CDATA string Name of the class used for {@link addCDATA()}
$childClass_Comment string Name of the class used for {@link addComment()}
$childClass_Conditional string Name of the class used for {@link addContional()}
$childClass_Doctype string Name of the class used for {@link addDoctype()}
$childClass_Text string Name of the class used for {@link addText()}
$childClass_XML string Name of the class used for {@link addXML()}
$children array Array of child nodes
$filter_map array Function map used for the selector filter
$parent DomNode Parent node, null if none
$parserClass string Name of the parser class
$selectClass string Name of the selector class
$self_close boolean Is node a self closing node? No closing tag if true.
$self_close_str string If self close, then this will be used to close the tag
$tag string Full tag name (including namespace)
$tag_ns array Namespace info for tag

Public Methods

Method Description
__construct ( string | array $tag, DomNode $parent ) Class constructor
__destruct ( ) Class destructor
__get ( $attribute ) : string Class magic get method, outputs {@link getAttribute()}
__invoke ( string $query = '*' ) : pQuery Class magic invoke method, performs {@link query()}.
__isset ( $attribute ) : boolean Class magic isset method, returns {@link hasAttribute()}
__set ( $attribute, $value ) Class magic set method, performs {@link setAttribute()}
__toString ( ) : string Class toString, outputs {@link $tag}
__unset ( $attribute ) Class magic unset method, performs {@link deleteAttribute()}
addASP ( $tag = '', $text = '', $attributes = [], &$offset = null ) #php5
addAttribute ( string $attr, string $val ) Add new attribute
addCDATA ( $text, &$offset = null ) #php5
addChild ( $tag, &$offset = null ) #php5
addClass ( string | array $className ) Add new class(es)
addComment ( $text, &$offset = null ) #php5
addConditional ( $condition, $hidden = true, &$offset = null ) #php5
addDoctype ( $dtd, &$offset = null ) #php5
addText ( $text, &$offset = null ) #php5
addXML ( $tag = 'xml', $text = '', $attributes = [], &$offset = null ) #php5
after ( $content )
append ( $content )
attr ( $name, $value = null )
attributeCount ( ) : integer Number of attributes
before ( $content )
changeParent ( $to, &$index = null ) #php5
childCount ( boolean $ignore_text_comments = false ) : integer Number of children in node
clear ( ) Deletes all child nodes from node
count ( )
delete ( ) Delete node from parent and clear node
deleteAttribute ( string | integer $attr, string $compare = 'total', boolean $case_sensitive = false ) Delete attribute(s)
deleteChild ( integer | DomNode $child, boolean $soft_delete = false ) Delete a child node
detach ( boolean $move_children_up = false ) Detach node from parent
dumpLocation ( ) : string Returns place in document
findChild ( DomNode $child ) : integer Find node in children
firstChild ( boolean $ignore_text_comments = false ) : DomNode First child node
getAttribute ( string | integer $attr, string $compare = 'total', boolean $case_sensitive = false ) : string | array Gets value(s) of attribute(s)
getAttributeNS ( string | integer $attr, string $compare = 'name', boolean $case_sensitive = false ) : string | array Gets namespace of attribute(s)
getChild ( integer | DomNode $child, boolean $ignore_text_comments = false ) : DomNode Get childnode
getChildrenByAttribute ( string $attribute, string $value, string $mode = 'equals', string $compare = 'total', boolean | integer $recursive = true ) : array Finds children that match a certain attribute
getChildrenByCallback ( callable $callback, boolean | integer $recursive = true, boolean $check_self = false ) : array Finds children using a callback function
getChildrenByClass ( string $class, boolean | integer $recursive = true ) : array Finds all children using class attribute
getChildrenByID ( string $id, boolean | integer $recursive = true ) : array Finds all children using ID attribute
getChildrenByMatch ( $conditions, boolean | integer $recursive = true, boolean $check_self = false, $custom_filters = [] ) : array Finds children using the {$link match()} function
getChildrenByName ( string $name, boolean | integer $recursive = true ) : array Finds all children using name attribute
getChildrenByTag ( string $tag, string $compare = 'total', boolean | integer $recursive = true ) : array Finds children that match a certain tag
getEncoding ( ) : string | boolean Try to determine the encoding of the current tag
getInnerText ( ) : string Similar to JavaScript innerText, will return (html formatted) content
getNamespace ( ) : string Get namespace of node
getNextSibling ( boolean $skip_text_comments = true ) : DomNode Get node next to current
getOuterText ( ) : string Similar to JavaScript outerText, will return full (html formatted) node
getPlainText ( ) : string Similar to JavaScript plainText, will return text in node (and subnodes)
getPlainTextUTF8 ( ) : string Return plaintext taking document encoding into account
getPreviousSibling ( boolean $skip_text_comments = true ) : DomNode Get node previous to current
getRoot ( ) : DomNode Get top parent
getSibling ( integer $offset = 1 ) : DomNode Get sibling node
getTag ( ) : string Get tagname of node (without namespace)
hasAttribute ( $attr, string $compare = 'total', boolean $case_sensitive = false ) : boolean Checks if node has attribute
hasChild ( DomNode $child ) : boolean Checks if node has another node as child
hasClass ( string $className ) : boolean Determine if node has a certain class
hasParent ( DomNode | string $tag = null, boolean $recursive = false ) : boolean Find out if node has (a certain) parent
html ( string | null $value = null ) : string Return html code of node
indent ( ) : integer Calculate indent of node (number of parent tags - 1)
index ( boolean $count_all = true ) : integer Index of node in parent
insertChild ( string | DomNode $tag, $index ) : DomNode Insert childnode
isComment ( ) : boolean Find out if node is comment
isParent ( DomNode | string $tag, boolean $recursive = false ) : boolean Find out if node is parent of a certain tag
isText ( ) : boolean Find out if node is text
isTextOrComment ( ) : boolean Find out if node is text or comment node
lastChild ( boolean $ignore_text_comments = false ) : DomNode Last child node
match ( $conditions, array $match = true, array $custom_filters = [] ) : boolean Checks if node matches certain conditions
move ( $to, &$new_index ) #php5
moveChildren ( $to, &$new_index, $start, $end ) #php5
prepend ( $content = null ) }
prop ( $name, $value = null )
query ( string $query = '*' ) : pquery\IQuery Performs a css query on the node.
remove ( $selector = null )
removeAttr ( $name )
removeClass ( string | array $className ) Remove clas(ses)
replaceWith ( $content )
select ( string $query = '*', integer | boolean $index = false, boolean | integer $recursive = true, boolean $check_self = false ) : DomNode[] | DomNode Performs css query on node
setAttribute ( string | integer $attr, $val, string $compare = 'total', boolean $case_sensitive = false ) Sets value(s) of attribute(s)
setAttributeNS ( string | integer $attr, string $namespace, string $compare = 'name', boolean $case_sensitive = false ) : boolean Sets namespace of attribute(s)
setIndex ( integer $index ) Change index of node in parent
setInnerText ( string $text, HtmlParserBase $parser = null ) : boolean | array Similar to JavaScript innerText, will replace child nodes with new text
setNamespace ( string $ns ) Set namespace of node
setOuterText ( string $text, HtmlParserBase $parser = null ) : boolean | array Similar to JavaScript outerText, will replace node (and child nodes) with new text
setPlainText ( string $text ) Similar to JavaScript plainText, will replace child nodes with new text (literal)
setTag ( string $tag, boolean $with_ns = false ) Set tag (with or without namespace)
tagName ( type $value = null ) : string | DomNode
text ( $value = null )
toString ( boolean $attributes = true, boolean | integer $recursive = true, boolean | integer $content_only = false ) : string Returns the node as string
toggleClass ( $classname, $switch = null )
typeIndex ( ) : integer Index of all similar nodes in parent
unwrap ( )
val ( $value = null )
wrap ( string | DomNode $node, integer $wrap_index, integer $node_index = null ) : DomNode Wrap node
wrapInner ( string | DomNode $node, integer $start, integer $end, integer $wrap_index, integer $node_index = null ) : DomNode Wrap child nodes

Protected Methods

Method Description
createNode ( string | DomNode $content ) : DomNode Create a {@link DomNode} from its string representation.
createNodes ( string | DomNode $content ) : DomNode[] Create an array of {@link DomNode} objects from their string representation.
filter_checked ( ) : boolean Checks if a node matches css query filter ":checked"
filter_comment ( ) : boolean Checks if node matches css query filter ":comment"
filter_contains ( string $text ) : boolean Checks if node matches css query filter ":contains(s)"
filter_element ( ) : boolean Checks if node matches css query filter ":element"
filter_empty ( ) : boolean Checks if node matches css query filter ":empty"
filter_even ( ) : boolean Checks if node matches css query filter ":even"
filter_every ( $n ) : boolean Checks if node matches css query filter ":every(n)"
filter_first ( ) : boolean Checks if node matches css query filter ":first"
filter_firsttype ( ) : boolean Checks if node matches css query filter ":first-of-type"
filter_gt ( string $n ) : boolean Checks if node matches css query filter ":gt(n)"
filter_has ( string $selector ) : boolean Checks if node matches css query filter ":has(s)"
filter_hastext ( ) : boolean Checks if node matches css query filter ":has-text"
filter_lang ( string $lang ) : boolean Checks if node matches css query filter ":lang(s)"
filter_last ( ) : boolean Checks if node matches css query filter ":last"
filter_lasttype ( ) : boolean Checks if node matches css query filter ":last-of-type"
filter_lt ( string $n ) : boolean Checks if node matches css query filter ":lt(n)"
filter_nchild ( string $n ) : boolean Checks if node matches css query filter ":nth-child(n)"
filter_nlastchild ( string $n ) : boolean Checks if node matches css query filter ":nth-last-child(n)"
filter_nlastype ( string $n ) : boolean Checks if node matches css query filter ":nth-last-of-type(n)"
filter_not ( string $selector ) : boolean Checks if node matches css query filter ":not(s)"
filter_notempty ( ) : boolean Checks if node matches css query filter ":not-empty"
filter_notext ( ) : boolean Checks if node matches css query filter ":no-text"
filter_ntype ( string $n ) : boolean Checks if node matches css query filter ":nth-of-type(n)"
filter_odd ( ) : boolean Checks if node matches css query filter ":odd"
filter_onlychild ( ) : boolean Checks if node matches css query filter ":only-child"
filter_onlytype ( ) : boolean Checks if node matches css query filter ":only-of-type"
filter_root ( ) : boolean Checks if node matches css query filter ":root"
filter_selected ( ) : boolean Checks if a node matches css query filter ":selected"
filter_text ( ) : boolean Checks if node matches css query filter ":text"
findAttribute ( string | integer $attr, string $compare = 'total', boolean $case_sensitive = false ) : array Find attribute using namespace, name or both
match_attributes ( array $attributes ) : boolean Checks if attributes match certain conditions
match_filters ( $conditions, array $custom_filters = [] ) : boolean Checks if node matches certain filters
match_tags ( array $tags ) : boolean Checks if tag matches certain conditions
toString_attributes ( ) : string Returns all the attributes and their values
toString_content ( boolean $attributes = true, boolean | integer $recursive = true, boolean $content_only = false ) : string Returns the content of the node (child tags and text)

Method Details

__construct() public method

Class constructor
public __construct ( string | array $tag, DomNode $parent )
$tag string | array Name of the tag, or array with taginfo (array( 'tag_name' => 'tag', 'self_close' => false, 'attributes' => array('attribute' => 'value')))
$parent DomNode Parent of node, null if none

__destruct() public method

Class destructor
public __destruct ( )

__get() public method

Class magic get method, outputs {@link getAttribute()}
public __get ( $attribute ) : string
return string

__invoke() public method

Class magic invoke method, performs {@link query()}.
public __invoke ( string $query = '*' ) : pQuery
$query string The css query to run on the nodes.
return pQuery

__isset() public method

Class magic isset method, returns {@link hasAttribute()}
public __isset ( $attribute ) : boolean
return boolean

__set() public method

Class magic set method, performs {@link setAttribute()}
public __set ( $attribute, $value )

__toString() public method

Class toString, outputs {@link $tag}
public __toString ( ) : string
return string

__unset() public method

Class magic unset method, performs {@link deleteAttribute()}
public __unset ( $attribute )

addASP() public method

#php5
public addASP ( $tag = '', $text = '', $attributes = [], &$offset = null )

addAttribute() public method

Add new attribute
public addAttribute ( string $attr, string $val )
$attr string
$val string

addCDATA() public method

#php5
public addCDATA ( $text, &$offset = null )

addChild() public method

#php5
public addChild ( $tag, &$offset = null )

addClass() public method

Add new class(es)
public addClass ( string | array $className )
$className string | array

addComment() public method

#php5
public addComment ( $text, &$offset = null )

addConditional() public method

#php5
public addConditional ( $condition, $hidden = true, &$offset = null )

addDoctype() public method

#php5
public addDoctype ( $dtd, &$offset = null )

addText() public method

#php5
public addText ( $text, &$offset = null )

addXML() public method

#php5
public addXML ( $tag = 'xml', $text = '', $attributes = [], &$offset = null )

after() public method

public after ( $content )

append() public method

public append ( $content )

attr() public method

public attr ( $name, $value = null )

attributeCount() public method

Number of attributes
public attributeCount ( ) : integer
return integer

before() public method

public before ( $content )

changeParent() public method

#php5
public changeParent ( $to, &$index = null )

childCount() public method

Number of children in node
public childCount ( boolean $ignore_text_comments = false ) : integer
$ignore_text_comments boolean Ignore text/comments with calculation
return integer

clear() public method

Deletes all child nodes from node
public clear ( )

count() public method

public count ( )

createNode() protected method

Create a {@link DomNode} from its string representation.
protected createNode ( string | DomNode $content ) : DomNode
$content string | DomNode
return DomNode

createNodes() protected method

Create an array of {@link DomNode} objects from their string representation.
protected createNodes ( string | DomNode $content ) : DomNode[]
$content string | DomNode
return DomNode[]

delete() public method

Delete node from parent and clear node
public delete ( )

deleteAttribute() public method

Delete attribute(s)
public deleteAttribute ( string | integer $attr, string $compare = 'total', boolean $case_sensitive = false )
$attr string | integer Negative int to count from end
$compare string Find node using "namespace", "name" or "total"
$case_sensitive boolean Compare with case sensitivity

deleteChild() public method

Delete a child node
public deleteChild ( integer | DomNode $child, boolean $soft_delete = false )
$child integer | DomNode Child(index) to delete, negative to count from end
$soft_delete boolean False to call {@link delete()} from child

detach() public method

Detach node from parent
See also: delete()
public detach ( boolean $move_children_up = false )
$move_children_up boolean Only detach current node and replace it with child nodes

dumpLocation() public method

Returns place in document
public dumpLocation ( ) : string
return string

filter_checked() protected method

Checks if a node matches css query filter ":checked"
See also: match()
protected filter_checked ( ) : boolean
return boolean

filter_comment() protected method

Checks if node matches css query filter ":comment"
See also: match()
protected filter_comment ( ) : boolean
return boolean

filter_contains() protected method

Checks if node matches css query filter ":contains(s)"
See also: match()
protected filter_contains ( string $text ) : boolean
$text string
return boolean

filter_element() protected method

Checks if node matches css query filter ":element"
See also: match()
protected filter_element ( ) : boolean
return boolean

filter_empty() protected method

Checks if node matches css query filter ":empty"
See also: match()
protected filter_empty ( ) : boolean
return boolean

filter_even() protected method

Checks if node matches css query filter ":even"
See also: match()
protected filter_even ( ) : boolean
return boolean

filter_every() protected method

Checks if node matches css query filter ":every(n)"
See also: match()
protected filter_every ( $n ) : boolean
return boolean

filter_first() protected method

Checks if node matches css query filter ":first"
See also: match()
protected filter_first ( ) : boolean
return boolean

filter_firsttype() protected method

Checks if node matches css query filter ":first-of-type"
See also: match()
protected filter_firsttype ( ) : boolean
return boolean

filter_gt() protected method

Checks if node matches css query filter ":gt(n)"
See also: match()
protected filter_gt ( string $n ) : boolean
$n string 0-based index
return boolean

filter_has() protected method

Checks if node matches css query filter ":has(s)"
See also: match()
protected filter_has ( string $selector ) : boolean
$selector string
return boolean

filter_hastext() protected method

Checks if node matches css query filter ":has-text"
See also: match()
protected filter_hastext ( ) : boolean
return boolean

filter_lang() protected method

Checks if node matches css query filter ":lang(s)"
See also: match()
protected filter_lang ( string $lang ) : boolean
$lang string
return boolean

filter_last() protected method

Checks if node matches css query filter ":last"
See also: match()
protected filter_last ( ) : boolean
return boolean

filter_lasttype() protected method

Checks if node matches css query filter ":last-of-type"
See also: match()
protected filter_lasttype ( ) : boolean
return boolean

filter_lt() protected method

Checks if node matches css query filter ":lt(n)"
See also: match()
protected filter_lt ( string $n ) : boolean
$n string 0-based index
return boolean

filter_nchild() protected method

Checks if node matches css query filter ":nth-child(n)"
See also: match()
protected filter_nchild ( string $n ) : boolean
$n string 1-based index
return boolean

filter_nlastchild() protected method

Checks if node matches css query filter ":nth-last-child(n)"
See also: match()
protected filter_nlastchild ( string $n ) : boolean
$n string 1-based index
return boolean

filter_nlastype() protected method

Checks if node matches css query filter ":nth-last-of-type(n)"
See also: match()
protected filter_nlastype ( string $n ) : boolean
$n string 1-based index
return boolean

filter_not() protected method

Checks if node matches css query filter ":not(s)"
See also: match()
protected filter_not ( string $selector ) : boolean
$selector string
return boolean

filter_notempty() protected method

Checks if node matches css query filter ":not-empty"
See also: match()
protected filter_notempty ( ) : boolean
return boolean

filter_notext() protected method

Checks if node matches css query filter ":no-text"
See also: match()
protected filter_notext ( ) : boolean
return boolean

filter_ntype() protected method

Checks if node matches css query filter ":nth-of-type(n)"
See also: match()
protected filter_ntype ( string $n ) : boolean
$n string 1-based index
return boolean

filter_odd() protected method

Checks if node matches css query filter ":odd"
See also: match()
protected filter_odd ( ) : boolean
return boolean

filter_onlychild() protected method

Checks if node matches css query filter ":only-child"
See also: match()
protected filter_onlychild ( ) : boolean
return boolean

filter_onlytype() protected method

Checks if node matches css query filter ":only-of-type"
See also: match()
protected filter_onlytype ( ) : boolean
return boolean

filter_root() protected method

Checks if node matches css query filter ":root"
See also: match()
protected filter_root ( ) : boolean
return boolean

filter_selected() protected method

Checks if a node matches css query filter ":selected"
See also: match()
protected filter_selected ( ) : boolean
return boolean

filter_text() protected method

Checks if node matches css query filter ":text"
See also: match()
protected filter_text ( ) : boolean
return boolean

findAttribute() protected method

Find attribute using namespace, name or both
protected findAttribute ( string | integer $attr, string $compare = 'total', boolean $case_sensitive = false ) : array
$attr string | integer Negative int to count from end
$compare string "namespace", "name" or "total"
$case_sensitive boolean Compare with case sensitivity
return array array('ns', 'attr', 'ns:attr', index)

findChild() public method

Find node in children
public findChild ( DomNode $child ) : integer
$child DomNode
return integer False if not found

firstChild() public method

First child node
public firstChild ( boolean $ignore_text_comments = false ) : DomNode
$ignore_text_comments boolean Ignore text/comments with index calculation
return DomNode

getAttribute() public method

Gets value(s) of attribute(s)
public getAttribute ( string | integer $attr, string $compare = 'total', boolean $case_sensitive = false ) : string | array
$attr string | integer Negative int to count from end
$compare string Find node using "namespace", "name" or "total"
$case_sensitive boolean Compare with case sensitivity
return string | array

getAttributeNS() public method

Gets namespace of attribute(s)
public getAttributeNS ( string | integer $attr, string $compare = 'name', boolean $case_sensitive = false ) : string | array
$attr string | integer Negative int to count from end
$compare string Find node using "namespace", "name" or "total"
$case_sensitive boolean Compare with case sensitivity
return string | array False if not found

getChild() public method

Get childnode
public getChild ( integer | DomNode $child, boolean $ignore_text_comments = false ) : DomNode
$child integer | DomNode Index, negative to count from end
$ignore_text_comments boolean Ignore text/comments with index calculation
return DomNode

getChildrenByAttribute() public method

Finds children that match a certain attribute
public getChildrenByAttribute ( string $attribute, string $value, string $mode = 'equals', string $compare = 'total', boolean | integer $recursive = true ) : array
$attribute string
$value string
$mode string Compare mode, "equals", "|=", "contains_regex", etc.
$compare string "total"/"namespace"/"name"
$recursive boolean | integer
return array

getChildrenByCallback() public method

Finds children using a callback function
public getChildrenByCallback ( callable $callback, boolean | integer $recursive = true, boolean $check_self = false ) : array
$callback callable Function($node) that returns a bool
$recursive boolean | integer Check recursively
$check_self boolean Include this node in search?
return array

getChildrenByClass() public method

Finds all children using class attribute
public getChildrenByClass ( string $class, boolean | integer $recursive = true ) : array
$class string
$recursive boolean | integer
return array

getChildrenByID() public method

Finds all children using ID attribute
public getChildrenByID ( string $id, boolean | integer $recursive = true ) : array
$id string
$recursive boolean | integer
return array

getChildrenByMatch() public method

Finds children using the {$link match()} function
public getChildrenByMatch ( $conditions, boolean | integer $recursive = true, boolean $check_self = false, $custom_filters = [] ) : array
$conditions See {$link match()}
$recursive boolean | integer Check recursively
$check_self boolean Include this node in search?
$custom_filters See {$link match()}
return array

getChildrenByName() public method

Finds all children using name attribute
public getChildrenByName ( string $name, boolean | integer $recursive = true ) : array
$name string
$recursive boolean | integer
return array

getChildrenByTag() public method

Finds children that match a certain tag
public getChildrenByTag ( string $tag, string $compare = 'total', boolean | integer $recursive = true ) : array
$tag string
$compare string "total"/"namespace"/"name"
$recursive boolean | integer
return array

getEncoding() public method

Try to determine the encoding of the current tag
public getEncoding ( ) : string | boolean
return string | boolean False if encoding could not be found

getInnerText() public method

Similar to JavaScript innerText, will return (html formatted) content
public getInnerText ( ) : string
return string

getNamespace() public method

Get namespace of node
See also: setNamespace()
public getNamespace ( ) : string
return string

getNextSibling() public method

Get node next to current
See also: getSibling()
See also: getPreviousSibling()
public getNextSibling ( boolean $skip_text_comments = true ) : DomNode
$skip_text_comments boolean
return DomNode Null if not found

getOuterText() public method

Similar to JavaScript outerText, will return full (html formatted) node
public getOuterText ( ) : string
return string

getPlainText() public method

Similar to JavaScript plainText, will return text in node (and subnodes)
public getPlainText ( ) : string
return string

getPlainTextUTF8() public method

Return plaintext taking document encoding into account
public getPlainTextUTF8 ( ) : string
return string

getPreviousSibling() public method

Get node previous to current
See also: getSibling()
See also: getNextSibling()
public getPreviousSibling ( boolean $skip_text_comments = true ) : DomNode
$skip_text_comments boolean
return DomNode Null if not found

getRoot() public method

Get top parent
public getRoot ( ) : DomNode
return DomNode Root, null if node has no parent

getSibling() public method

Get sibling node
public getSibling ( integer $offset = 1 ) : DomNode
$offset integer Offset from current node
return DomNode Null if not found

getTag() public method

Get tagname of node (without namespace)
See also: setTag()
public getTag ( ) : string
return string

hasAttribute() public method

Checks if node has attribute
public hasAttribute ( $attr, string $compare = 'total', boolean $case_sensitive = false ) : boolean
$compare string Find node using "namespace", "name" or "total"
$case_sensitive boolean Compare with case sensitivity
return boolean

hasChild() public method

Checks if node has another node as child
public hasChild ( DomNode $child ) : boolean
$child DomNode
return boolean

hasClass() public method

Determine if node has a certain class
public hasClass ( string $className ) : boolean
$className string
return boolean

hasParent() public method

Find out if node has (a certain) parent
public hasParent ( DomNode | string $tag = null, boolean $recursive = false ) : boolean
$tag DomNode | string Match against parent, string to match tag, object to fully match node, null to return if node has parent
$recursive boolean
return boolean

html() public method

Return html code of node
See also: toString()
public html ( string | null $value = null ) : string
$value string | null The value to set or null to get the value.
return string

indent() public method

Calculate indent of node (number of parent tags - 1)
public indent ( ) : integer
return integer

index() public method

Index of node in parent
public index ( boolean $count_all = true ) : integer
$count_all boolean True to count all tags, false to ignore text and comments
return integer -1 if not found

insertChild() public method

Insert childnode
public insertChild ( string | DomNode $tag, $index ) : DomNode
$tag string | DomNode Tagname or object
return DomNode Added node

isComment() public method

Find out if node is comment
public isComment ( ) : boolean
return boolean

isParent() public method

Find out if node is parent of a certain tag
See also: hasParent()
public isParent ( DomNode | string $tag, boolean $recursive = false ) : boolean
$tag DomNode | string Match against parent, string to match tag, object to fully match node
$recursive boolean
return boolean

isText() public method

Find out if node is text
public isText ( ) : boolean
return boolean

isTextOrComment() public method

Find out if node is text or comment node
public isTextOrComment ( ) : boolean
return boolean

lastChild() public method

Last child node
public lastChild ( boolean $ignore_text_comments = false ) : DomNode
$ignore_text_comments boolean Ignore text/comments with index calculation
return DomNode

match() public method

Checks if node matches certain conditions
public match ( $conditions, array $match = true, array $custom_filters = [] ) : boolean
$match array Should conditions evaluate to true?
$custom_filters array Custom map next to {@link $filter_map}
return boolean

match_attributes() protected method

Checks if attributes match certain conditions
See also: match()
protected match_attributes ( array $attributes ) : boolean
$attributes array array('attr' => 'val') or array(array( 'operator_value' => 'equals'/'='/'contains_regex'/etc 'attribute' => 'attr', 'value' => 'val', 'match' => true, 'operator_result' => 'or'/'and', 'compare' => 'total'/'namespace'/'name', 'case_sensitive' => true))
return boolean

match_filters() protected method

Checks if node matches certain filters
See also: match()
protected match_filters ( $conditions, array $custom_filters = [] ) : boolean
$custom_filters array Custom map next to {@link $filter_map}
return boolean

match_tags() protected method

Checks if tag matches certain conditions
See also: match()
protected match_tags ( array $tags ) : boolean
$tags array array('tag1', 'tag2') or array(array( 'tag' => 'tag1', 'operator' => 'or'/'and', 'compare' => 'total'/'namespace'/'name', 'case_sensitive' => true))
return boolean

move() public method

#php5
public move ( $to, &$new_index )

moveChildren() public method

#php5
public moveChildren ( $to, &$new_index, $start, $end )

prepend() public method

}
public prepend ( $content = null )

prop() public method

public prop ( $name, $value = null )

query() public method

Performs a css query on the node.
public query ( string $query = '*' ) : pquery\IQuery
$query string
return pquery\IQuery Returns the matching nodes from the query.

remove() public method

public remove ( $selector = null )

removeAttr() public method

public removeAttr ( $name )

removeClass() public method

Remove clas(ses)
public removeClass ( string | array $className )
$className string | array

replaceWith() public method

public replaceWith ( $content )

select() public method

Performs css query on node
public select ( string $query = '*', integer | boolean $index = false, boolean | integer $recursive = true, boolean $check_self = false ) : DomNode[] | DomNode
$query string
$index integer | boolean True to return node instead of array if only 1 match, false to return array, int to return match at index, negative int to count from end
$recursive boolean | integer
$check_self boolean Include this node in search or only search child nodes
return DomNode[] | DomNode Returns an array of matching {@link DomNode} objects or a single {@link DomNode} if `$index` is not false.

setAttribute() public method

Sets value(s) of attribute(s)
public setAttribute ( string | integer $attr, $val, string $compare = 'total', boolean $case_sensitive = false )
$attr string | integer Negative int to count from end
$compare string Find node using "namespace", "name" or "total"
$case_sensitive boolean Compare with case sensitivity

setAttributeNS() public method

Sets namespace of attribute(s)
public setAttributeNS ( string | integer $attr, string $namespace, string $compare = 'name', boolean $case_sensitive = false ) : boolean
$attr string | integer Negative int to count from end
$namespace string
$compare string Find node using "namespace", "name" or "total"
$case_sensitive boolean Compare with case sensitivity
return boolean

setIndex() public method

Change index of node in parent
public setIndex ( integer $index )
$index integer New index

setInnerText() public method

Similar to JavaScript innerText, will replace child nodes with new text
public setInnerText ( string $text, HtmlParserBase $parser = null ) : boolean | array
$text string
$parser HtmlParserBase Null to auto create instance
return boolean | array True on succeed, array with errors on failure

setNamespace() public method

Set namespace of node
See also: getNamespace()
public setNamespace ( string $ns )
$ns string

setOuterText() public method

Similar to JavaScript outerText, will replace node (and child nodes) with new text
public setOuterText ( string $text, HtmlParserBase $parser = null ) : boolean | array
$text string
$parser HtmlParserBase Null to auto create instance
return boolean | array True on succeed, array with errors on failure

setPlainText() public method

Similar to JavaScript plainText, will replace child nodes with new text (literal)
public setPlainText ( string $text )
$text string

setTag() public method

Set tag (with or without namespace)
See also: getTag()
public setTag ( string $tag, boolean $with_ns = false )
$tag string
$with_ns boolean Does $tag include namespace?

tagName() public method

public tagName ( type $value = null ) : string | DomNode
$value type
return string | DomNode

text() public method

public text ( $value = null )

toString() public method

Returns the node as string
public toString ( boolean $attributes = true, boolean | integer $recursive = true, boolean | integer $content_only = false ) : string
$attributes boolean Print attributes (of child tags)
$recursive boolean | integer How many sub-levels of child tags to print. True for all.
$content_only boolean | integer Only print text, false will print tags too.
return string

toString_attributes() protected method

Returns all the attributes and their values
protected toString_attributes ( ) : string
return string

toString_content() protected method

Returns the content of the node (child tags and text)
protected toString_content ( boolean $attributes = true, boolean | integer $recursive = true, boolean $content_only = false ) : string
$attributes boolean Print attributes of child tags
$recursive boolean | integer How many sublevels of childtags to print. True for all.
$content_only boolean Only print text, false will print tags too.
return string

toggleClass() public method

public toggleClass ( $classname, $switch = null )

typeIndex() public method

Index of all similar nodes in parent
public typeIndex ( ) : integer
return integer -1 if not found

unwrap() public method

public unwrap ( )

val() public method

public val ( $value = null )

wrap() public method

Wrap node
public wrap ( string | DomNode $node, integer $wrap_index, integer $node_index = null ) : DomNode
$node string | DomNode Wrapping node, string to create new element node
$wrap_index integer Index to insert current node in wrapping node, -1 to append
$node_index integer Index to insert wrapping node, null to keep at same position
return DomNode Wrapping node

wrapInner() public method

Wrap child nodes
public wrapInner ( string | DomNode $node, integer $start, integer $end, integer $wrap_index, integer $node_index = null ) : DomNode
$node string | DomNode Wrapping node, string to create new element node
$start integer Index from child node where to start wrapping, 0 for first element
$end integer Index from child node where to end wrapping, -1 for last element
$wrap_index integer Index to insert in wrapping node, -1 to append
$node_index integer Index to insert current node, null to keep at same position
return DomNode Wrapping node

Property Details

$attribute_shorttag public property

Use short tags for attributes? If true, then attributes with values equal to the attribute name will not output the value, e.g. selected="selected" will be selected.
public bool $attribute_shorttag
return boolean

$attributes public property

Attributes of node
See also: getAttribute()
See also: setAttribute()
public array $attributes
return array

$attributes_ns public property

Namespace info for attributes
See also: findAttribute()
public array $attributes_ns
return array

$childClass public property

Name of the class used for {@link addChild()}
public string $childClass
return string

$childClass_ASP public property

Name of the class used for {@link addASP()}
public string $childClass_ASP
return string

$childClass_CDATA public property

Name of the class used for {@link addCDATA()}
public string $childClass_CDATA
return string

$childClass_Comment public property

Name of the class used for {@link addComment()}
public string $childClass_Comment
return string

$childClass_Conditional public property

Name of the class used for {@link addContional()}
public string $childClass_Conditional
return string

$childClass_Doctype public property

Name of the class used for {@link addDoctype()}
public string $childClass_Doctype
return string

$childClass_Text public property

Name of the class used for {@link addText()}
public string $childClass_Text
return string

$childClass_XML public property

Name of the class used for {@link addXML()}
public string $childClass_XML
return string

$children public property

Array of child nodes
See also: childCount()
See also: getChild()
See also: addChild()
See also: deleteChild()
public array $children
return array

$filter_map public property

Function map used for the selector filter
public array $filter_map
return array

$parent public property

Parent node, null if none
See also: changeParent()
public DomNode,pquery $parent
return DomNode

$parserClass public property

Name of the parser class
See also: setOuterText()
See also: setInnerText()
public string $parserClass
return string

$selectClass public property

Name of the selector class
See also: select()
public string $selectClass
return string

$self_close public property

Is node a self closing node? No closing tag if true.
public bool $self_close
return boolean

$self_close_str public property

If self close, then this will be used to close the tag
public string $self_close_str
return string

$tag public property

Full tag name (including namespace)
See also: getTagName()
See also: getNamespace()
public string $tag
return string

$tag_ns public property

Namespace info for tag
public array $tag_ns
return array