PHP Класс 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.
См. также: qp()
Наследование: implements QueryPath\Query, implements IteratorAggregate, implements Countable
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$length The number of current matches.

Защищенные свойства (Protected)

Свойство Тип Описание
$document The base DOMDocument.
$last The last array of matches.
$matches The array of matches.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
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 )

Описание методов

__call() публичный Метод

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() публичный Метод

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() публичный Метод

Typically, a new DOMQuery is created by QueryPath::with(), QueryPath::withHTML(), qp(), or htmlqp().
См. также: 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() публичный Метод

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.
См. также: append()
См. также: after()
См. также: andSelf()
См. также: end()
public add ( string $selector )
$selector string A valid selector.

addClass() публичный Метод

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.
См. также: css()
См. также: attr()
См. также: removeClass()
См. также: hasClass()
public addClass ( string $class )
$class string The name of the class.

after() публичный Метод

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.
См. также: before()
См. также: append()
public after ( mixed $data )
$data mixed The data to be appended.

andSelf() публичный Метод

Example:
См. также: add()
См. также: end()
public andSelf ( )

append() публичный Метод

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.
См. также: appendTo()
См. также: prepend()
public append ( mixed $data )
$data mixed This can be either a string (the usual case), or a DOM Element.

appendTo() публичный Метод

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.
См. также: append()
См. также: prependTo()
public appendTo ( DOMQuery $dest )
$dest DOMQuery A DOMQuery object that will be appended to.

attach() публичный Метод

If no selector is specified, this will remove all current matches from the document.
См. также: replaceAll()
См. также: replaceWith()
См. также: removeChildren()
С версии: 2.1
Автор: eabrand
public attach ( DOMQuery $dest )
$dest DOMQuery A DOMQuery Selector.

attr() публичный Метод

- 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.
См. также: removeAttr()
См. также: tag()
См. также: hasAttr()
См. также: 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).
Результат mixed If this was a setter request, return the DOMQuery object. If this was an access request (getter), return the string value.

before() публичный Метод

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().
См. также: insertBefore()
См. также: after()
См. также: append()
См. также: 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() публичный Метод

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:
См. также: cloneAll()
См. также: find()
С версии: 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() публичный Метод

If a selector is provided, the list of children will be filtered through the selector.
См. также: removeChildren()
См. также: parent()
См. также: parents()
См. также: next()
См. также: prev()
public children ( string $selector = null )
$selector string A valid selector.

childrenText() публичный Метод

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.
Результат string The concatenated values of all children.

cloneAll() публичный Метод

Perform a deep clone of each node in the DOMQuery.
См. также: qp()
public cloneAll ( )

closest() публичный Метод

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.
С версии: 2.0
public closest ( string $selector )
$selector string A CSS Selector to match.

contents() публичный Метод

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.
См. также: find()
См. также: text()
См. также: html()
См. также: innerHTML()
См. также: xml()
См. также: innerXML()
public contents ( )

count() публичный Метод

Since DOMQuery is Countable, the PHP count() function can also be used on a DOMQuery.
public count ( ) : integer
Результат integer The number of matches in the DOMQuery.

css() публичный Метод

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() публичный Метод

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.
См. также: http://en.wikipedia.org/wiki/Data:_URL
См. также: attr()
С версии: 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() публичный Метод

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() защищенный Метод

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.
Результат array Returns an array of DOM nodes.

detach() публичный Метод

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.
См. также: replaceAll()
См. также: replaceWith()
См. также: removeChildren()
С версии: 2.1
Автор: eabrand
public detach ( string $selector = null )
$selector string A CSS Selector.

document() публичный Метод

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
Результат DOMDocument

each() публичный Метод

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.
См. также: eachLambda()
См. также: filter()
См. также: map()
public each ( callback $callback )
$callback callback The callback to run.

eachLambda() публичный Метод

An each() iterator that takes a lambda function.
См. также: each()
См. также: filterLambda()
См. также: filterCallback()
См. также: map()
Устаревший: 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() публичный Метод

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.
См. также: removeChildren()
Устаревший: The removeChildren() function is the preferred method.
С версии: 2.1
Автор: eabrand
public emptyElement ( )

end() публичный Метод

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:
См. также: andSelf()
См. также: add()
Устаревший: This function will be removed.
public end ( )

eq() публичный Метод

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()}.
См. также: get()
См. также: is()
См. также: end()
public eq ( $index )
$index The index of the element to keep. The rest will be discarded.

even() публичный Метод

Get the even elements, so counter-intuitively 1, 3, 5, etc.
См. также: removeChildren()
См. также: parent()
См. также: parents()
См. также: next()
См. также: prev()
С версии: 2.1
Автор: eabrand
public even ( )

filter() публичный Метод

Use this, for example, to find all elements with a class, or with certain children.
См. также: filterLambda()
См. также: filterCallback()
См. также: map()
См. также: find()
См. также: is()
public filter ( string $selector )
$selector string The selector to use as a filter.

filterCallback() публичный Метод

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.
См. также: filter()
См. также: filterLambda()
См. также: map()
См. также: is()
См. также: find()
public filterCallback ( $callback )

filterLambda() публичный Метод

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:
См. также: filter()
См. также: map()
См. также: mapLambda()
См. также: filterCallback()
public filterLambda ( string $fn )
$fn string Inline lambda function in a string.

filterPreg() публичный Метод

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:
См. также: filter()
См. также: filterCallback()
См. также: preg_match()
public filterPreg ( string $regex )
$regex string A regular expression.

find() публичный Метод

Given a CSS Selector, find matching items.
См. также: filter()
См. также: is()
public find ( string $selector )
$selector string CSS 3 Selector

findInPlace() публичный Метод

public findInPlace ( $selector )

first() публичный Метод

Get the first matching element.
См. также: next()
См. также: prev()
С версии: 2.1
Автор: eabrand
public first ( )

firstChild() публичный Метод

Get the first child of the matching element.
См. также: next()
См. также: prev()
С версии: 2.1
Автор: eabrand
public firstChild ( )

get() публичный Метод

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}.
См. также: eq()
См. также: 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.
Результат 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() публичный Метод

Get an iterator for the matches in this object.
public getIterator ( ) : Iterable
Результат Iterable Returns an iterator.

getOptions() публичный Метод

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.
См. также: qp()
С версии: 2.0
public getOptions ( ) : array
Результат array An associative array of options, calculated from defaults and overridden options.

has() публичный Метод

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.
С версии: 2.1
Автор: 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() публичный Метод

This returns TRUE if all selected items have the attribute, or FALSE if at least one item does not have the attribute.
См. также: attr()
См. также: hasClass()
С версии: 2.0
public hasAttr ( string $attrName ) : boolean
$attrName string The attribute name.
Результат boolean TRUE if all matches have the attribute, FALSE otherwise.

hasClass() публичный Метод

Returns TRUE if any of the elements in the DOMQuery have the specified class.
См. также: addClass()
См. также: removeClass()
public hasClass ( string $class ) : boolean
$class string The name of the class.
Результат boolean TRUE if the class exists in one or more of the elements, FALSE otherwise.

html() публичный Метод

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:
См. также: xml()
См. также: text()
См. также: contents()
public html ( string $markup = null ) : mixed
$markup string The text to insert.
Результат mixed A string if no markup was passed, or a DOMQuery if markup was passed.

index() публичный Метод

Given a DOMElement, get the index from the matches. This is the converse of {@link get()}.
См. также: get()
См. также: is()
public index ( DOMElement $subject ) : mixed
$subject DOMElement The item to match.
Результат 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() публичный Метод

This behaves the way jQuery's @codehtml()@endcode function behaves. This gets all children of the first match in DOMQuery. Consider this fragment:
См. также: html()
См. также: innerXML()
См. также: innerXHTML()
С версии: 2.0
public innerHTML ( ) : string
Результат string Returns a string representation of the child nodes of the first matched element.

innerXHTML() публичный Метод

This will return the children of the present match. For an example, see {@link innerHTML()}.
См. также: innerHTML()
См. также: innerXML()
С версии: 2.0
public innerXHTML ( ) : string
Результат string Returns a string of XHTML that represents the children of the present node.

innerXML() публичный Метод

This will return the children of the present match. For an example, see {@link innerHTML()}.
См. также: innerHTML()
См. также: innerXHTML()
С версии: 2.0
public innerXML ( ) : string
Результат string Returns a string of XHTML that represents the children of the present node.

insertAfter() публичный Метод

Insert the contents of the current DOMQuery after the nodes in the destination DOMQuery object.
См. также: after()
См. также: insertBefore()
См. также: append()
public insertAfter ( DOMQuery $dest )
$dest DOMQuery Destination object where the current elements will be deposited.

insertBefore() публичный Метод

The items are inserted before each element in the given DOMQuery document. That is, they will be siblings with the current elements.
См. также: before()
См. также: insertAfter()
См. также: appendTo()
public insertBefore ( DOMQuery $dest )
$dest DOMQuery Destination DOMQuery document.

inst() защищенный Метод

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

is() публичный Метод

Unlike jQuery's version, this supports full selectors (not just simple ones).
См. также: get()
См. также: 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.
Результат boolean TRUE if one or more elements match. FALSE if no match is found.

isXMLish() защищенный Метод

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() публичный Метод

Get the last matching element.
См. также: next()
См. также: prev()
С версии: 2.1
Автор: eabrand
public last ( )

lastChild() публичный Метод

Get the last child of the matching element.
См. также: next()
См. также: prev()
С версии: 2.1
Автор: eabrand
public lastChild ( )

map() публичный Метод

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.
См. также: DOMQuery::get()
См. также: filter()
См. также: 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() публичный Метод

If a selector is provided, the next matching sibling will be returned.
См. также: nextAll()
См. также: prev()
См. также: children()
См. также: contents()
См. также: parent()
См. также: parents()
public next ( string $selector = null )
$selector string A CSS3 selector.

nextAll() публичный Метод

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.
См. также: next()
См. также: prevAll()
См. также: children()
См. также: siblings()
public nextAll ( string $selector = null )
$selector string A valid CSS 3 selector.

nextUntil() публичный Метод

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.
См. также: next()
См. также: prevAll()
См. также: children()
См. также: siblings()
С версии: 2.1
Автор: eabrand
public nextUntil ( string $selector = null )
$selector string A valid CSS 3 selector.

not() публичный Метод

Filter a list to contain only items that do NOT match.
См. также: 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() публичный Метод

Get the odd elements, so counter-intuitively 0, 2, 4, etc.
См. также: removeChildren()
См. также: parent()
См. также: parents()
См. также: next()
См. также: prev()
С версии: 2.1
Автор: eabrand
public odd ( )

parent() публичный Метод

If a selector is passed, this will return the nearest matching parent for each element in the DOMQuery.
См. также: children()
См. также: siblings()
См. также: parents()
public parent ( string $selector = null )
$selector string A valid CSS3 selector.

parents() публичный Метод

If a selector is present, only matching ancestors will be retrieved.
См. также: parent()
См. также: siblings()
См. также: children()
public parents ( string $selector = null )
$selector string A valid CSS 3 Selector.

parentsUntil() публичный Метод

If a selector is present, only matching ancestors will be retrieved.
См. также: parent()
См. также: siblings()
См. также: children()
С версии: 2.1
Автор: eabrand
public parentsUntil ( string $selector = null )
$selector string A valid CSS 3 Selector.

prepareInsert() защищенный Метод

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.
Результат mixed Returns the prepared item.

prepend() публичный Метод

The markup will be inserted into each match in the set.
См. также: append()
См. также: before()
См. также: after()
См. также: prependTo()
public prepend ( mixed $data )
$data mixed This can be either a string (the usual case), or a DOM Element.

prependTo() публичный Метод

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.
См. также: insertBefore()
См. также: insertAfter()
См. также: prepend()
См. также: appendTo()
public prependTo ( DOMQuery $dest )
$dest DOMQuery The destination DOMQuery object.

prev() публичный Метод

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).
См. также: prevAll()
См. также: next()
См. также: siblings()
См. также: children()
public prev ( string $selector = null )
$selector string A valid CSS 3 selector.

prevAll() публичный Метод

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

prevUntil() публичный Метод

For each element in the DOMQuery, get all previous siblings. If a selector is provided, only matching siblings will be retrieved.
См. также: prev()
См. также: nextAll()
См. также: siblings()
См. также: contents()
См. также: children()
С версии: 2.1
Автор: eabrand
public prevUntil ( string $selector = null )
$selector string A valid CSS 3 selector.

remove() публичный Метод

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.
См. также: replaceAll()
См. также: replaceWith()
См. также: removeChildren()
public remove ( string $selector = null )
$selector string A CSS Selector.

removeAttr() публичный Метод

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.
См. также: attr()
public removeAttr ( string $name )
$name string Name of the parameter to remove.

removeChildren() публичный Метод

This is equivalent to jQuery's empty() function. (However, empty() is a PHP built-in, and cannot be used as a method name.)
См. также: replaceWith()
См. также: replaceAll()
См. также: remove()
public removeChildren ( )

removeClass() публичный Метод

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:
См. также: attr()
См. также: addClass()
См. также: hasClass()
public removeClass ( string $class = false )
$class string The class name to remove.

replaceAll() публичный Метод

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.
См. также: remove()
См. также: replaceWith()
Устаревший: 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() публичный Метод

Replace the existing element(s) in the list with a new one.
См. также: append()
См. также: prepend()
См. также: before()
См. также: after()
См. также: remove()
См. также: 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() публичный Метод

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

siblings() публичный Метод

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.
См. также: contents()
См. также: children()
См. также: parent()
См. также: parents()
public siblings ( string $selector = null )
$selector string If the optional selector is provided, siblings will be filtered through this expression.

size() публичный Метод

Note that there is no length property on this object.
Устаревший: QueryPath now implements Countable, so use count().
public size ( ) : integer
Результат integer Number of items in the object.

slice() публичный Метод

Narrow the items in this object down to only a slice of the starting items.
См. также: 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() публичный Метод

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() публичный Метод

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.
См. также: replaceAll()
См. также: replaceWith()
public tag ( ) : string
Результат string The tag name of the first element in the list.

text() публичный Метод

Get or set the text contents of a node.
См. также: html()
См. также: xml()
См. также: 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.
Результат mixed A DOMQuery if $text is set, or the text content if no text is passed in as a pram.

textAfter() публичный Метод

public textAfter ( $text = null )

textBefore() публичный Метод

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.
Результат mixed Returns the DOMQuery object if $text was set, and returns a string (possibly empty) if no param is passed.

textImplode() публичный Метод

This has the effect of looping through all children, retrieving their text content, and then concatenating the text with a separator.
См. также: implode()
См. также: text()
С версии: 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.
Результат string The text contents, concatenated together with the given separator between every pair of items.

toArray() публичный Метод

Compatibility function for jQuery 1.4, but identical to calling {@link get()} with no parameters.
public toArray ( ) : array
Результат array An array of DOMNodes (typically DOMElements).

top() публичный Метод

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() публичный Метод

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:
См. также: wrap()
С версии: 2.1
Автор: mbutcher
public unwrap ( )

val() публичный Метод

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.
См. также: attr()
Устаревший: Just use attr(). There's no reason to use this on the server.
public val ( string $value = null ) : mixed
$value string
Результат 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() публичный Метод

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.)
См. также: wrapAll()
См. также: wrapInner()
public wrap ( mixed $markup )
$markup mixed Markup that will wrap each element in the current list.

wrapAll() публичный Метод

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.)
См. также: wrap()
См. также: wrapInner()
public wrapAll ( string $markup )
$markup string Markup that will wrap all elements in the current list.

wrapInner() публичный Метод

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.)
См. также: wrap()
См. также: wrapAll()
public wrapInner ( string $markup )
$markup string Markup that will wrap children of each element in the current list.

writeHTML() публичный Метод

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.
См. также: html()
См. также: 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() публичный Метод

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