PHP Class QueryPath\DOMQuery

To create a new DOMQuery, use QueryPath::with() or qp() function. If you are new to these documents, start at the QueryPath.php page. There you will find a quick guide to the tools contained in this project. A note on serialization: DOMQuery uses DOM classes internally, and those do not serialize well at all. In addition, DOMQuery may contain many extensions, and there is no guarantee that extensions can serialize. The moral of the story: Don't serialize DOMQuery.
See also: qp()
Inheritance: implements QueryPath\Query, implements IteratorAggregate, implements Countable
显示文件 Open project: microweber/microweber Class Usage Examples

Public Properties

Property Type Description
$length The number of current matches.

Protected Properties

Property Type Description
$document The base DOMDocument.
$last The last array of matches.
$matches The array of matches.

Public Methods

Method Description
__call ( $name, $arguments ) Call extension methods.
__clone ( ) Clone the DOMQuery.
__construct ( mixed $document = null, string $string = null, array $options = [] ) Constructor.
add ( string $selector ) Add more elements to the current set of matches.
addClass ( string $class ) Add a class to all elements in the current DOMQuery.
after ( mixed $data ) Insert the given data after each element in the current DOMQuery object.
andSelf ( ) Combine the current and previous set of matched objects.
append ( mixed $data ) Insert the given markup as the last child.
appendTo ( DOMQuery $dest ) Append the current elements to the destination passed into the function.
attach ( DOMQuery $dest ) Attach any items from the list if they match the selector.
attr ( mixed $name = null, string $value = null ) : mixed Get/set an attribute.
before ( mixed $data ) Insert the given data before each element in the current set of matches.
branch ( string $selector = null ) Branch the base DOMQuery into another one with the same matches.
children ( string $selector = null ) Get the children of the elements in the DOMQuery object.
childrenText ( string $separator = ' ' ) : string Get the text contents from just child elements.
cloneAll ( ) Perform a deep clone of each node in the DOMQuery.
closest ( string $selector ) Find the closest element matching the selector.
contents ( ) Get all child nodes (not just elements) of all items in the matched set.
count ( ) : integer Get the number of elements currently wrapped by this object.
css ( mixed $name = null, string $value = '' ) Set/get a CSS value for the current element(s).
dataURL ( string $attr, mixed $data = null, string $mime = 'application/octet-stream', resource $context = null ) Insert or retrieve a Data URL.
deepest ( ) Reduce the set of matches to the deepest child node in the tree.
detach ( string $selector = null ) Detach any items from the list if they match the selector.
document ( ) : DOMDocument Get the DOMDocument that we currently work with.
each ( callback $callback ) Run a callback on each item in the list of items.
eachLambda ( string $lambda ) An each() iterator that takes a lambda function.
emptyElement ( ) Empty everything within the specified element.
end ( ) Revert to the previous set of matches.
eq ( $index ) Reduce the matched set to just one.
even ( ) Get the even elements, so counter-intuitively 1, 3, 5, etc.
filter ( string $selector ) Filter a list down to only elements that match the selector.
filterCallback ( $callback ) Filter based on a callback function.
filterLambda ( string $fn ) Filter based on a lambda function.
filterPreg ( string $regex ) Use regular expressions to filter based on the text content of matched elements.
find ( string $selector ) Given a CSS Selector, find matching items.
findInPlace ( $selector )
first ( ) Get the first matching element.
firstChild ( ) Get the first child of the matching element.
get ( integer $index = null, boolean $asObject = false ) : mixed Get one or all elements from this object.
getIterator ( ) : Iterable Get an iterator for the matches in this object.
getOptions ( ) : array Get the effective options for the current DOMQuery object.
has ( mixed $contained ) Reduce the elements matched by DOMQuery to only those which contain the given item.
hasAttr ( string $attrName ) : boolean Check to see if the given attribute is present.
hasClass ( string $class ) : boolean Returns TRUE if any of the elements in the DOMQuery have the specified class.
html ( string $markup = null ) : mixed Set or get the markup for an element.
index ( DOMElement $subject ) : mixed Get an item's index.
innerHTML ( ) : string Fetch the HTML contents INSIDE of the first DOMQuery item.
innerXHTML ( ) : string Fetch child (inner) nodes of the first match.
innerXML ( ) : string Fetch child (inner) nodes of the first match.
insertAfter ( DOMQuery $dest ) Insert the contents of the current DOMQuery after the nodes in the destination DOMQuery object.
insertBefore ( DOMQuery $dest ) Insert the current elements into the destination document.
is ( string $selector ) : boolean Given a selector, this checks to see if the current set has one or more matches.
last ( ) Get the last matching element.
lastChild ( ) Get the last child of the matching element.
map ( callback $callback ) Run a function on each item in a set.
next ( string $selector = null ) Get the next sibling of each element in the DOMQuery.
nextAll ( string $selector = null ) Get all siblings after an element.
nextUntil ( string $selector = null ) Get all siblings after an element until the selector is reached.
not ( string $selector ) Filter a list to contain only items that do NOT match.
odd ( ) Get the odd elements, so counter-intuitively 0, 2, 4, etc.
parent ( string $selector = null ) Get the immediate parent of each element in the DOMQuery.
parents ( string $selector = null ) Get all ancestors of each element in the DOMQuery.
parentsUntil ( string $selector = null ) Get all ancestors of each element in the DOMQuery until the selector is reached.
prepend ( mixed $data ) Insert the given markup as the first child.
prependTo ( DOMQuery $dest ) Take all nodes in the current object and prepend them to the children nodes of each matched node in the passed-in DOMQuery object.
prev ( string $selector = null ) Get the next sibling before each element in the DOMQuery.
prevAll ( string $selector = null ) Get the previous siblings for each element in the DOMQuery.
prevUntil ( string $selector = null ) Get the previous siblings for each element in the DOMQuery until the selector is reached.
remove ( string $selector = null ) Remove any items from the list if they match the selector.
removeAttr ( string $name ) Remove the named attribute from all elements in the current DOMQuery.
removeChildren ( ) Remove all child nodes.
removeClass ( string $class = false ) Remove the named class from any element in the DOMQuery that has it.
replaceAll ( string $selector, DOMDocument $document ) This replaces everything that matches the selector with the first value in the current list.
replaceWith ( mixed $new ) Replace the existing element(s) in the list with a new one.
setMatches ( $matches, $unique = true ) EXPERT: Be very, very careful using this.
siblings ( string $selector = null ) Get a list of siblings for elements currently wrapped by this object.
size ( ) : integer Get the number of elements currently wrapped by this object.
slice ( integer $start, integer $length ) Narrow the items in this object down to only a slice of the starting items.
sort ( callback $comparator, boolean $modifyDOM = false ) Sort the contents of the QueryPath object.
tag ( ) : string The tag name of the first element in the list.
text ( string $text = null ) : mixed Get or set the text contents of a node.
textAfter ( $text = null )
textBefore ( string $text = null ) : mixed Get or set the text before each selected item.
textImplode ( string $sep = ', ', boolean $filterEmpties = true ) : string Retrieve the text of each match and concatenate them with the given separator.
toArray ( ) : array Get all current elements wrapped in an array.
top ( string $selector = null ) Select the root element of the document.
unwrap ( ) Remove the parent element from the selected node or nodes.
val ( string $value = null ) : mixed Set or get the value of an element's 'value' attribute.
wrap ( mixed $markup ) Wrap each element inside of the given markup.
wrapAll ( string $markup ) Wrap all elements inside of the given markup.
wrapInner ( string $markup ) Wrap the child elements of each item in the list with the given markup.
writeHTML ( string $path = null ) Writes HTML to output.
writeXHTML ( string $path = null ) Write an XHTML file to output.
writeXML ( string $path = null, integer $options = null ) Send the XML document to the client.
xhtml ( string $markup = null ) : mixed Set or get XHTML markup for an element or elements.
xinclude ( ) On an XML document, load all XIncludes.
xml ( string $markup = null ) : mixed Set or get the XML markup for an element or elements.
xpath ( string $query, array $options = [] ) Execute an XPath query and store the results in the QueryPath.

Protected Methods

Method Description
deepestNode ( DOMNode $ele, integer $depth, mixed $current = null, DOMNode &$deepest = null ) : array A depth-checking function. Typically, it only needs to be invoked with the first parameter. The rest are used for recursion.
inst ( $matches, $selector, $options )
isXMLish ( $string ) Determine whether a given string looks like XML or not.
prepareInsert ( mixed $item ) : mixed Prepare an item for insertion into a DOM.

Private Methods

Method Description
getFirstMatch ( ) Convenience function for getNthMatch(0).
getNthMatch ( $index ) A utility function for retriving a match by index.
noMatches ( ) Set the match monitor to empty.
parseXMLFile ( string $filename, integer $flags = null, resource $context = null ) Parse an XML or HTML file.
parseXMLString ( $string, $flags = null )

Method Details

__call() public method

This function is used to invoke extension methods. It searches the registered extenstensions for a matching function name. If one is found, it is executed with the arguments in the $arguments array.
public __call ( $name, $arguments )

__clone() public method

This makes a deep clone of the elements inside of the DOMQuery. This clones only the QueryPathImpl, not all of the decorators. The clone operator in PHP should handle the cloning of the decorators.
public __clone ( )

__construct() public method

Typically, a new DOMQuery is created by QueryPath::with(), QueryPath::withHTML(), qp(), or htmlqp().
See also: qp()
public __construct ( mixed $document = null, string $string = null, array $options = [] )
$document mixed A document-like object.
$string string A CSS 3 Selector
$options array An associative array of options.

add() public method

This begins the new query at the top of the DOM again. The results found when running this selector are then merged into the existing results. In this way, you can add additional elements to the existing set.
See also: append()
See also: after()
See also: andSelf()
See also: end()
public add ( string $selector )
$selector string A valid selector.

addClass() public method

This searchers for a class attribute on each item wrapped by the current DOMNode object. If no attribute is found, a new one is added and its value is set to $class. If a class attribute is found, then the value is appended on to the end.
See also: css()
See also: attr()
See also: removeClass()
See also: hasClass()
public addClass ( string $class )
$class string The name of the class.

after() public method

This inserts the element as a peer to the currently matched elements. Contrast this with {@link append()}, which inserts the data as children of matched elements.
See also: before()
See also: append()
public after ( mixed $data )
$data mixed The data to be appended.

andSelf() public method

Example:
See also: add()
See also: end()
public andSelf ( )

append() public method

The markup will be inserted into each match in the set. The same element cannot be inserted multiple times into a document. DOM documents do not allow a single object to be inserted multiple times into the DOM. To insert the same XML repeatedly, we must first clone the object. This has one practical implication: Once you have inserted an element into the object, you cannot further manipulate the original element and expect the changes to be replciated in the appended object. (They are not the same -- there is no shared reference.) Instead, you will need to retrieve the appended object and operate on that.
See also: appendTo()
See also: prepend()
public append ( mixed $data )
$data mixed This can be either a string (the usual case), or a DOM Element.

appendTo() public method

This cycles through all of the current matches and appends them to the context given in $destination. If a selector is provided then the $destination is queried (using that selector) prior to the data being appended. The data is then appended to the found items.
See also: append()
See also: prependTo()
public appendTo ( DOMQuery $dest )
$dest DOMQuery A DOMQuery object that will be appended to.

attach() public method

If no selector is specified, this will remove all current matches from the document.
See also: replaceAll()
See also: replaceWith()
See also: removeChildren()
Since: 2.1
Author: eabrand
public attach ( DOMQuery $dest )
$dest DOMQuery A DOMQuery Selector.

attr() public method

- If no parameters are specified, this returns an associative array of all name/value pairs. - If both $name and $value are set, then this will set the attribute name/value pair for all items in this object. - If $name is set, and is an array, then all attributes in the array will be set for all items in this object. - If $name is a string and is set, then the attribute value will be returned. When an attribute value is retrieved, only the attribute value of the FIRST match is returned.
See also: removeAttr()
See also: tag()
See also: hasAttr()
See also: hasClass()
public attr ( mixed $name = null, string $value = null ) : mixed
$name mixed The name of the attribute or an associative array of name/value pairs.
$value string A value (used only when setting an individual property).
return mixed If this was a setter request, return the DOMQuery object. If this was an access request (getter), return the string value.

before() public method

This will take the give data (XML or HTML) and put it before each of the items that the DOMQuery object currently contains. Contrast this with after().
See also: insertBefore()
See also: after()
See also: append()
See also: prepend()
public before ( mixed $data )
$data mixed The data to be inserted. This can be XML in a string, a DomFragment, a DOMElement, or the other usual suspects. (See {@link qp()}).

branch() public method

This function makes a copy of the DOMQuery object, but keeps the new copy (initially) pointed at the same matches. This object can then be queried without changing the original DOMQuery. However, changes to the elements inside of this DOMQuery will show up in the DOMQuery from which it is branched. Compare this operation with {@link cloneAll()}. The cloneAll() call takes the current DOMNode object and makes a copy of all of its matches. You continue to operate on the same DOMNode object, but the elements inside of the DOMQuery are copies of those before the call to cloneAll(). This, on the other hand, copies the DOMQuery, but keeps valid references to the document and the wrapped elements. A new query branch is created, but any changes will be written back to the same document. In practice, this comes in handy when you want to do multiple queries on a part of the document, but then return to a previous set of matches. (see {@link QPTPL} for examples of this in practice). Example:
See also: cloneAll()
See also: find()
Since: 1.1
public branch ( string $selector = null )
$selector string If a selector is passed in, an additional {@link find()} will be executed on the branch before it is returned. (Added in QueryPath 2.0.)

children() public method

If a selector is provided, the list of children will be filtered through the selector.
See also: removeChildren()
See also: parent()
See also: parents()
See also: next()
See also: prev()
public children ( string $selector = null )
$selector string A valid selector.

childrenText() public method

This is a specialized variant of textImplode() that implodes text for just the child elements of the current element.
public childrenText ( string $separator = ' ' ) : string
$separator string The separator that will be inserted between found text content.
return string The concatenated values of all children.

cloneAll() public method

Perform a deep clone of each node in the DOMQuery.
See also: qp()
public cloneAll ( )

closest() public method

This finds the closest match in the ancestry chain. It first checks the present element. If the present element does not match, this traverses up the ancestry chain (e.g. checks each parent) looking for an item that matches. It is provided for jQuery 1.3 compatibility.
Since: 2.0
public closest ( string $selector )
$selector string A CSS Selector to match.

contents() public method

It gets only the immediate children, not all nodes in the subtree. This does not process iframes. Xinclude processing is dependent on the DOM implementation and configuration.
See also: find()
See also: text()
See also: html()
See also: innerHTML()
See also: xml()
See also: innerXML()
public contents ( )

count() public method

Since DOMQuery is Countable, the PHP count() function can also be used on a DOMQuery.
public count ( ) : integer
return integer The number of matches in the DOMQuery.

css() public method

This sets the CSS value for each element in the DOMQuery object. It does this by setting (or getting) the style attribute (without a namespace). For example, consider this code:
public css ( mixed $name = null, string $value = '' )
$name mixed If this is a string, it will be used as a CSS name. If it is an array, this will assume it is an array of name/value pairs of CSS rules. It will apply all rules to all elements in the set.
$value string The value to set. This is only set if $name is a string.

dataURL() public method

When called with just $attr, it will fetch the result, attempt to decode it, and return an array with the MIME type and the application data. When called with both $attr and $data, it will inject the data into all selected elements So @code$qp->dataURL('src', file_get_contents('my.png'), 'image/png')@endcode will inject the given PNG image into the selected elements. The current implementation only knows how to encode and decode Base 64 data. Note that this is known *not* to work on IE 6, but should render fine in other browsers.
See also: http://en.wikipedia.org/wiki/Data:_URL
See also: attr()
Since: 2.1
public dataURL ( string $attr, mixed $data = null, string $mime = 'application/octet-stream', resource $context = null )
$attr string The name of the attribute.
$data mixed The contents to inject as the data. The value can be any one of the following: - A URL: If this is given, then the subsystem will read the content from that URL. THIS MUST BE A FULL URL, not a relative path. - A string of data: If this is given, then the subsystem will encode the string. - A stream or file handle: If this is given, the stream's contents will be encoded and inserted as data. (Note that we make the assumption here that you would never want to set data to be a URL. If this is an incorrect assumption, file a bug.)
$mime string The MIME type of the document.
$context resource A valid context. Use this only if you need to pass a stream context. This is only necessary if $data is a URL. (See {@link stream_context_create()}).

deepest() public method

This loops through the matches and looks for the deepest child node of all of the matches. "Deepest", here, is relative to the nodes in the list. It is calculated as the distance from the starting node to the most distant child node. In other words, it is not necessarily the farthest node from the root element, but the farthest note from the matched element. In the case where there are multiple nodes at the same depth, all of the nodes at that depth will be included.
public deepest ( )

deepestNode() protected method

A depth-checking function. Typically, it only needs to be invoked with the first parameter. The rest are used for recursion.
protected deepestNode ( DOMNode $ele, integer $depth, mixed $current = null, DOMNode &$deepest = null ) : array
$ele DOMNode The element.
$depth integer The depth guage
$current mixed The current set.
$deepest DOMNode A reference to the current deepest node.
return array Returns an array of DOM nodes.

detach() public method

In other words, each item that matches the selector will be removed from the DOM document. The returned DOMQuery wraps the list of removed elements. If no selector is specified, this will remove all current matches from the document.
See also: replaceAll()
See also: replaceWith()
See also: removeChildren()
Since: 2.1
Author: eabrand
public detach ( string $selector = null )
$selector string A CSS Selector.

document() public method

This returns the current DOMDocument. Any changes made to this document will be accessible to DOMQuery, as both will share access to the same object.
public document ( ) : DOMDocument
return DOMDocument

each() public method

Rules of the callback: - A callback is passed two variables: $index and $item. (There is no special treatment of $this, as there is in jQuery.) - You will want to pass $item by reference if it is not an object (DOMNodes are all objects). - A callback that returns FALSE will stop execution of the each() loop. This works like break in a standard loop. - A TRUE return value from the callback is analogous to a continue statement. - All other return values are ignored.
See also: eachLambda()
See also: filter()
See also: map()
public each ( callback $callback )
$callback callback The callback to run.

eachLambda() public method

An each() iterator that takes a lambda function.
See also: each()
See also: filterLambda()
See also: filterCallback()
See also: map()
Deprecation: Since PHP 5.3 supports anonymous functions -- REAL Lambdas -- this method is not necessary and should be avoided.
public eachLambda ( string $lambda )
$lambda string The lambda function. This will be passed ($index, &$item).

emptyElement() public method

A convenience function for removeChildren(). This is equivalent to jQuery's empty() function. However, empty is a built-in in PHP, and cannot be used as a function name.
See also: removeChildren()
Deprecation: The removeChildren() function is the preferred method.
Since: 2.1
Author: eabrand
public emptyElement ( )

end() public method

DEPRECATED Do not use. This will revert back to the last set of matches (before the last "destructive" set of operations). This undoes any change made to the set of matched objects. Functions like find() and filter() change the list of matched objects. The end() function will revert back to the last set of matched items. Note that functions that modify the document, but do not change the list of matched objects, are not "destructive". Thus, calling append('something')->end() will not undo the append() call. Only one level of changes is stored. Reverting beyond that will result in an empty set of matches. Example:
See also: andSelf()
See also: add()
Deprecation: This function will be removed.
public end ( )

eq() public method

This will take a matched set and reduce it to just one item -- the item at the index specified. This is a destructive operation, and can be undone with {@link end()}.
See also: get()
See also: is()
See also: end()
public eq ( $index )
$index The index of the element to keep. The rest will be discarded.

even() public method

Get the even elements, so counter-intuitively 1, 3, 5, etc.
See also: removeChildren()
See also: parent()
See also: parents()
See also: next()
See also: prev()
Since: 2.1
Author: eabrand
public even ( )

filter() public method

Use this, for example, to find all elements with a class, or with certain children.
See also: filterLambda()
See also: filterCallback()
See also: map()
See also: find()
See also: is()
public filter ( string $selector )
$selector string The selector to use as a filter.

filterCallback() public method

A callback may be any of the following: - a function: 'my_func'. - an object/method combo: $obj, 'myMethod' - a class/method combo: 'MyClass', 'myMethod' Note that classes are passed in strings. Objects are not. Each callback is passed to arguments: - $index: The index position of the object in the array. - $item: The item to be operated upon. If the callback function returns FALSE, the item will be removed from the set of matches. Otherwise the item will be considered a match and left alone.
See also: filter()
See also: filterLambda()
See also: map()
See also: is()
See also: find()
public filterCallback ( $callback )

filterLambda() public method

The function string will be executed as if it were the body of a function. It is passed two arguments: - $index: The index of the item. - $item: The current Element. If the function returns boolean FALSE, the item will be removed from the list of elements. Otherwise it will be kept. Example:
See also: filter()
See also: map()
See also: mapLambda()
See also: filterCallback()
public filterLambda ( string $fn )
$fn string Inline lambda function in a string.

filterPreg() public method

Only items that match the given regular expression will be kept. All others will be removed. The regular expression is run against the text content (the PCDATA) of the elements. This is a way of filtering elements based on their content. Example:
See also: filter()
See also: filterCallback()
See also: preg_match()
public filterPreg ( string $regex )
$regex string A regular expression.

find() public method

Given a CSS Selector, find matching items.
See also: filter()
See also: is()
public find ( string $selector )
$selector string CSS 3 Selector

findInPlace() public method

public findInPlace ( $selector )

first() public method

Get the first matching element.
See also: next()
See also: prev()
Since: 2.1
Author: eabrand
public first ( )

firstChild() public method

Get the first child of the matching element.
See also: next()
See also: prev()
Since: 2.1
Author: eabrand
public firstChild ( )

get() public method

When called with no paramaters, this returns all objects wrapped by the DOMQuery. Typically, these are DOMElement objects (unless you have used map(), xpath(), or other methods that can select non-elements). When called with an index, it will return the item in the DOMQuery with that index number. Calling this method does not change the DOMQuery (e.g. it is non-destructive). You can use qp()->get() to iterate over all elements matched. You can also iterate over qp() itself (DOMQuery implementations must be Traversable). In the later case, though, each item will be wrapped in a DOMQuery object. To learn more about iterating in QueryPath, see {@link examples/techniques.php}.
See also: eq()
See also: SplObjectStorage
public get ( integer $index = null, boolean $asObject = false ) : mixed
$index integer If specified, then only this index value will be returned. If this index is out of bounds, a NULL will be returned.
$asObject boolean If this is TRUE, an SplObjectStorage object will be returned instead of an array. This is the preferred method for extensions to use.
return mixed If an index is passed, one element will be returned. If no index is present, an array of all matches will be returned.

getIterator() public method

Get an iterator for the matches in this object.
public getIterator ( ) : Iterable
return Iterable Returns an iterator.

getOptions() public method

This returns an associative array of all of the options as set for the current DOMQuery object. This includes default options, options directly passed in via {@link qp()} or the constructor, an options set in the QueryPath::Options object. The order of merging options is this: - Options passed in using qp() are highest priority, and will override other options. - Options set with QueryPath::Options will override default options, but can be overridden by options passed into qp(). - Default options will be used when no overrides are present. This function will return the options currently used, with the above option overriding having been calculated already.
See also: qp()
Since: 2.0
public getOptions ( ) : array
return array An associative array of options, calculated from defaults and overridden options.

has() public method

There are two ways in which this is different from jQuery's implementation: - We allow ANY DOMNode, not just DOMElements. That means this will work on processor instructions, text nodes, comments, etc. - Unlike jQuery, this implementation of has() follows QueryPath standard behavior and modifies the existing object. It does not create a brand new object.
Since: 2.1
Author: eabrand
public has ( mixed $contained )
$contained mixed - If $contained is a CSS selector (e.g. '#foo'), this will test to see if the current DOMQuery has any elements that contain items that match the selector. - If $contained is a DOMNode, then this will test to see if THE EXACT DOMNode exists in the currently matched elements. (Note that you cannot match across DOM trees, even if it is the same document.)

hasAttr() public method

This returns TRUE if all selected items have the attribute, or FALSE if at least one item does not have the attribute.
See also: attr()
See also: hasClass()
Since: 2.0
public hasAttr ( string $attrName ) : boolean
$attrName string The attribute name.
return boolean TRUE if all matches have the attribute, FALSE otherwise.

hasClass() public method

Returns TRUE if any of the elements in the DOMQuery have the specified class.
See also: addClass()
See also: removeClass()
public hasClass ( string $class ) : boolean
$class string The name of the class.
return boolean TRUE if the class exists in one or more of the elements, FALSE otherwise.

html() public method

If $markup is set, then the giving markup will be injected into each item in the set. All other children of that node will be deleted, and this new code will be the only child or children. The markup MUST BE WELL FORMED. If no markup is given, this will return a string representing the child markup of the first node. Important: This differs from jQuery's html() function. This function returns the current node and all of its children. jQuery returns only the children. This means you do not need to do things like this:
See also: xml()
See also: text()
See also: contents()
public html ( string $markup = null ) : mixed
$markup string The text to insert.
return mixed A string if no markup was passed, or a DOMQuery if markup was passed.

index() public method

Given a DOMElement, get the index from the matches. This is the converse of {@link get()}.
See also: get()
See also: is()
public index ( DOMElement $subject ) : mixed
$subject DOMElement The item to match.
return mixed The index as an integer (if found), or boolean FALSE. Since 0 is a valid index, you should use strong equality (===) to test..

innerHTML() public method

This behaves the way jQuery's @codehtml()@endcode function behaves. This gets all children of the first match in DOMQuery. Consider this fragment:
See also: html()
See also: innerXML()
See also: innerXHTML()
Since: 2.0
public innerHTML ( ) : string
return string Returns a string representation of the child nodes of the first matched element.

innerXHTML() public method

This will return the children of the present match. For an example, see {@link innerHTML()}.
See also: innerHTML()
See also: innerXML()
Since: 2.0
public innerXHTML ( ) : string
return string Returns a string of XHTML that represents the children of the present node.

innerXML() public method

This will return the children of the present match. For an example, see {@link innerHTML()}.
See also: innerHTML()
See also: innerXHTML()
Since: 2.0
public innerXML ( ) : string
return string Returns a string of XHTML that represents the children of the present node.

insertAfter() public method

Insert the contents of the current DOMQuery after the nodes in the destination DOMQuery object.
See also: after()
See also: insertBefore()
See also: append()
public insertAfter ( DOMQuery $dest )
$dest DOMQuery Destination object where the current elements will be deposited.

insertBefore() public method

The items are inserted before each element in the given DOMQuery document. That is, they will be siblings with the current elements.
See also: before()
See also: insertAfter()
See also: appendTo()
public insertBefore ( DOMQuery $dest )
$dest DOMQuery Destination DOMQuery document.

inst() protected method

protected inst ( $matches, $selector, $options )

is() public method

Unlike jQuery's version, this supports full selectors (not just simple ones).
See also: get()
See also: eq()
public is ( string $selector ) : boolean
$selector string The selector to search for. As of QueryPath 2.1.1, this also supports passing a DOMNode object.
return boolean TRUE if one or more elements match. FALSE if no match is found.

isXMLish() protected method

Basically, this scans a portion of the supplied string, checking to see if it has a tag-like structure. It is possible to "confuse" this, which may subsequently result in parse errors, but in the vast majority of cases, this method serves as a valid inicator of whether or not the content looks like XML. Things that are intentional excluded: - plain text with no markup. - strings that look like filesystem paths. Subclasses SHOULD NOT OVERRIDE THIS. Altering it may be altering core assumptions about how things work. Instead, classes should override the constructor and pass in only one of the parsed types that this class expects.
protected isXMLish ( $string )

last() public method

Get the last matching element.
See also: next()
See also: prev()
Since: 2.1
Author: eabrand
public last ( )

lastChild() public method

Get the last child of the matching element.
See also: next()
See also: prev()
Since: 2.1
Author: eabrand
public lastChild ( )

map() public method

The mapping callback can return anything. Whatever it returns will be stored as a match in the set, though. This means that afer a map call, there is no guarantee that the elements in the set will behave correctly with other DOMQuery functions. Callback rules: - If the callback returns NULL, the item will be removed from the array. - If the callback returns an array, the entire array will be stored in the results. - If the callback returns anything else, it will be appended to the array of matches.
See also: DOMQuery::get()
See also: filter()
See also: find()
public map ( callback $callback )
$callback callback The function or callback to use. The callback will be passed two params: - $index: The index position in the list of items wrapped by this object. - $item: The current item.

next() public method

If a selector is provided, the next matching sibling will be returned.
See also: nextAll()
See also: prev()
See also: children()
See also: contents()
See also: parent()
See also: parents()
public next ( string $selector = null )
$selector string A CSS3 selector.

nextAll() public method

For each element in the DOMQuery, get all siblings that appear after it. If a selector is passed in, then only siblings that match the selector will be included.
See also: next()
See also: prevAll()
See also: children()
See also: siblings()
public nextAll ( string $selector = null )
$selector string A valid CSS 3 selector.

nextUntil() public method

For each element in the DOMQuery, get all siblings that appear after it. If a selector is passed in, then only siblings that match the selector will be included.
See also: next()
See also: prevAll()
See also: children()
See also: siblings()
Since: 2.1
Author: eabrand
public nextUntil ( string $selector = null )
$selector string A valid CSS 3 selector.

not() public method

Filter a list to contain only items that do NOT match.
See also: find()
public not ( string $selector )
$selector string A selector to use as a negation filter. If the filter is matched, the element will be removed from the list.

odd() public method

Get the odd elements, so counter-intuitively 0, 2, 4, etc.
See also: removeChildren()
See also: parent()
See also: parents()
See also: next()
See also: prev()
Since: 2.1
Author: eabrand
public odd ( )

parent() public method

If a selector is passed, this will return the nearest matching parent for each element in the DOMQuery.
See also: children()
See also: siblings()
See also: parents()
public parent ( string $selector = null )
$selector string A valid CSS3 selector.

parents() public method

If a selector is present, only matching ancestors will be retrieved.
See also: parent()
See also: siblings()
See also: children()
public parents ( string $selector = null )
$selector string A valid CSS 3 Selector.

parentsUntil() public method

If a selector is present, only matching ancestors will be retrieved.
See also: parent()
See also: siblings()
See also: children()
Since: 2.1
Author: eabrand
public parentsUntil ( string $selector = null )
$selector string A valid CSS 3 Selector.

prepareInsert() protected method

This handles a variety of boilerplate tasks that need doing before an indeterminate object can be inserted into a DOM tree. - If item is a string, this is converted into a document fragment and returned. - If item is a DOMQuery, then all items are retrieved and converted into a document fragment and returned. - If the item is a DOMNode, it is imported into the current DOM if necessary. - If the item is a SimpleXMLElement, it is converted into a DOM node and then imported.
protected prepareInsert ( mixed $item ) : mixed
$item mixed Item to prepare for insert.
return mixed Returns the prepared item.

prepend() public method

The markup will be inserted into each match in the set.
See also: append()
See also: before()
See also: after()
See also: prependTo()
public prepend ( mixed $data )
$data mixed This can be either a string (the usual case), or a DOM Element.

prependTo() public method

This will iterate through each item in the current DOMQuery object and add each item to the beginning of the children of each element in the passed-in DOMQuery object.
See also: insertBefore()
See also: insertAfter()
See also: prepend()
See also: appendTo()
public prependTo ( DOMQuery $dest )
$dest DOMQuery The destination DOMQuery object.

prev() public method

For each element in the DOMQuery, this retrieves the previous sibling (if any). If a selector is supplied, it retrieves the first matching sibling (if any is found).
See also: prevAll()
See also: next()
See also: siblings()
See also: children()
public prev ( string $selector = null )
$selector string A valid CSS 3 selector.

prevAll() public method

For each element in the DOMQuery, get all previous siblings. If a selector is provided, only matching siblings will be retrieved.
See also: prev()
See also: nextAll()
See also: siblings()
See also: contents()
See also: children()
public prevAll ( string $selector = null )
$selector string A valid CSS 3 selector.

prevUntil() public method

For each element in the DOMQuery, get all previous siblings. If a selector is provided, only matching siblings will be retrieved.
See also: prev()
See also: nextAll()
See also: siblings()
See also: contents()
See also: children()
Since: 2.1
Author: eabrand
public prevUntil ( string $selector = null )
$selector string A valid CSS 3 selector.

remove() public method

In other words, each item that matches the selector will be remove from the DOM document. The returned DOMQuery wraps the list of removed elements. If no selector is specified, this will remove all current matches from the document.
See also: replaceAll()
See also: replaceWith()
See also: removeChildren()
public remove ( string $selector = null )
$selector string A CSS Selector.

removeAttr() public method

This will remove any attribute with the given name. It will do this on each item currently wrapped by DOMQuery. As is the case in jQuery, this operation is not considered destructive.
See also: attr()
public removeAttr ( string $name )
$name string Name of the parameter to remove.

removeChildren() public method

This is equivalent to jQuery's empty() function. (However, empty() is a PHP built-in, and cannot be used as a method name.)
See also: replaceWith()
See also: replaceAll()
See also: remove()
public removeChildren ( )

removeClass() public method

This may result in the entire class attribute being removed. If there are other items in the class attribute, though, they will not be removed. Example: Consider this XML:
See also: attr()
See also: addClass()
See also: hasClass()
public removeClass ( string $class = false )
$class string The class name to remove.

replaceAll() public method

This is the reverse of replaceWith. Unlike jQuery, DOMQuery cannot assume a default document. Consequently, you must specify the intended destination document. If it is omitted, the present document is assumed to be tthe document. However, that can result in undefined behavior if the selector and the replacement are not sufficiently distinct.
See also: remove()
See also: replaceWith()
Deprecation: Due to the fact that this is not a particularly friendly method, and that it can be easily replicated using {@see \replaceWith()}, it is to be considered deprecated.
public replaceAll ( string $selector, DOMDocument $document )
$selector string The selector.
$document DOMDocument The destination document.

replaceWith() public method

Replace the existing element(s) in the list with a new one.
See also: append()
See also: prepend()
See also: before()
See also: after()
See also: remove()
See also: replaceAll()
public replaceWith ( mixed $new )
$new mixed A DOMElement or XML in a string. This will replace all elements currently wrapped in the DOMQuery object.

setMatches() public method

A utility function for setting the current set of matches. It makes sure the last matches buffer is set (for end() and andSelf()).
Since: 2.0
public setMatches ( $matches, $unique = true )

siblings() public method

This will compile a list of every sibling of every element in the current list of elements. Note that if two siblings are present in the DOMQuery object to begin with, then both will be returned in the matched set, since they are siblings of each other. In other words,if the matches contain a and b, and a and b are siblings of each other, than running siblings will return a set that contains both a and b.
See also: contents()
See also: children()
See also: parent()
See also: parents()
public siblings ( string $selector = null )
$selector string If the optional selector is provided, siblings will be filtered through this expression.

size() public method

Note that there is no length property on this object.
Deprecation: QueryPath now implements Countable, so use count().
public size ( ) : integer
return integer Number of items in the object.

slice() public method

Narrow the items in this object down to only a slice of the starting items.
See also: array_slice()
public slice ( integer $start, integer $length )
$start integer Where in the list of matches to begin the slice.
$length integer The number of items to include in the slice. If nothing is specified, the all remaining matches (from $start onward) will be included in the sliced list.

sort() public method

By default, this does not change the order of the elements in the DOM. Instead, it just sorts the internal list. However, if TRUE is passed in as the second parameter then QueryPath will re-order the DOM, too.
public sort ( callback $comparator, boolean $modifyDOM = false )
$comparator callback A callback. This will be called during sorting to compare two DOMNode objects.
$modifyDOM boolean If this is TRUE, the sorted results will be inserted back into the DOM at the position of the original first element.

tag() public method

This returns the tag name of the first element in the list of matches. If the list is empty, an empty string will be used.
See also: replaceAll()
See also: replaceWith()
public tag ( ) : string
return string The tag name of the first element in the list.

text() public method

Get or set the text contents of a node.
See also: html()
See also: xml()
See also: contents()
public text ( string $text = null ) : mixed
$text string If this is not NULL, this value will be set as the text of the node. It will replace any existing content.
return mixed A DOMQuery if $text is set, or the text content if no text is passed in as a pram.

textAfter() public method

public textAfter ( $text = null )

textBefore() public method

If $text is passed in, the text is inserted before each currently selected item. If no text is given, this will return the concatenated text after each selected element.
public textBefore ( string $text = null ) : mixed
$text string If this is set, it will be inserted before each node in the current set of selected items.
return mixed Returns the DOMQuery object if $text was set, and returns a string (possibly empty) if no param is passed.

textImplode() public method

This has the effect of looping through all children, retrieving their text content, and then concatenating the text with a separator.
See also: implode()
See also: text()
Since: 2.0
public textImplode ( string $sep = ', ', boolean $filterEmpties = true ) : string
$sep string The string used to separate text items. The default is a comma followed by a space.
$filterEmpties boolean If this is true, empty items will be ignored.
return string The text contents, concatenated together with the given separator between every pair of items.

toArray() public method

Compatibility function for jQuery 1.4, but identical to calling {@link get()} with no parameters.
public toArray ( ) : array
return array An array of DOMNodes (typically DOMElements).

top() public method

This sets the current match to the document's root element. For practical purposes, this is the same as:
public top ( string $selector = null )
$selector string A selector. If this is supplied, QueryPath will navigate to the document root and then run the query. (Added in QueryPath 2.0 Beta 2)

unwrap() public method

This takes the given list of nodes and "unwraps" them, moving them out of their parent node, and then deleting the parent node. For example, consider this:
See also: wrap()
Since: 2.1
Author: mbutcher
public unwrap ( )

val() public method

The 'value' attribute is common in HTML form elements. This is a convenience function for accessing the values. Since this is not common task on the server side, this method may be removed in future releases. (It is currently provided for jQuery compatibility.) If a value is provided in the params, then the value will be set for all matches. If no params are given, then the value of the first matched element will be returned. This may be NULL.
See also: attr()
Deprecation: Just use attr(). There's no reason to use this on the server.
public val ( string $value = null ) : mixed
$value string
return mixed Returns a DOMQuery if a string was passed in, and a string if no string was passed in. In the later case, an error will produce NULL.

wrap() public method

Markup is usually a string, but it can also be a DOMNode, a document fragment, a SimpleXMLElement, or another DOMNode object (in which case the first item in the list will be used.)
See also: wrapAll()
See also: wrapInner()
public wrap ( mixed $markup )
$markup mixed Markup that will wrap each element in the current list.

wrapAll() public method

So all elements will be grouped together under this single marked up item. This works by first determining the parent element of the first item in the list. It then moves all of the matching elements under the wrapper and inserts the wrapper where that first element was found. (This is in accordance with the way jQuery works.) Markup is usually XML in a string, but it can also be a DOMNode, a document fragment, a SimpleXMLElement, or another DOMNode object (in which case the first item in the list will be used.)
See also: wrap()
See also: wrapInner()
public wrapAll ( string $markup )
$markup string Markup that will wrap all elements in the current list.

wrapInner() public method

Markup is usually a string, but it can also be a DOMNode, a document fragment, a SimpleXMLElement, or another DOMNode object (in which case the first item in the list will be used.)
See also: wrap()
See also: wrapAll()
public wrapInner ( string $markup )
$markup string Markup that will wrap children of each element in the current list.

writeHTML() public method

HTML is formatted as HTML 4.01, without strict XML unary tags. This is for legacy HTML content. Modern XHTML should be written using {@link toXHTML()}. Write the document to stdout (usually the client) or to a file.
See also: html()
See also: innerHTML()
public writeHTML ( string $path = null )
$path string The path to the file into which the XML should be written. if this is NULL, data will be written to STDOUT, which is usually sent to the remote browser.

writeXHTML() public method

Typically, you should use this instead of {@link writeHTML()}. Currently, this functions identically to {@link toXML()} except that it always uses closing tags (e.g. always @code@endcode, never @code