Download the PHP package scotteh/php-dom-wrapper without Composer

On this page you can find all versions of the php package scotteh/php-dom-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-dom-wrapper

PHP DOM Wrapper

Intro

PHP DOM Wrapper is a simple DOM wrapper library to manipulate and traverse HTML documents. Based around jQuery's manipulation and traversal methods, largely mimicking the behaviour of it's jQuery counterparts.

Author

Requirements

Install

Install with Composer.

Autoloading

This library requires an autoloader, if you aren't already using one you can include Composers autoloader.

Methods

Manipulation

Method jQuery Equivalent (if different)
addClass()
follow() after()
appendWith() append()
appendTo()
attr()
clone()
destroy() remove()
detach()
empty()
hasClass()
html()
precede() before()
prependWith() prepend()
prependTo()
removeAttr()
removeClass()
substituteWith() replaceWith()
text()
unwrap()
wrap()
wrapAll()
wrapInner()

Traversal

Method jQuery Equivalent (if different)
add()
children()
closest()
contents()
eq()
filter()
find()
first()
has()
is()
last()
map()
following() next()
followingAll() nextAll()
followingUntil() nextUntil()
not()
parent()
parents()
parentsUntil()
preceding() prev()
precedingAll() prevAll()
precedingUntil() prevUntil()
siblings()
slice()

Other

Method jQuery Equivalent (if different)
count() length (property)
each()

Usage

Example #1:


Methods

Manipulation

addClass

Example

Result:


follow

Insert the argument as a sibling directly after each of the nodes operated on.

Example

Result:


appendWith

Example

Result:


appendTo

Example

Result:


attr

Example #1 (Set)

Result:

Example #2 (Get)

Result:


precede

Insert the argument as a sibling just before each of the nodes operated on.

Example

Result:


clone

Example

Result:


destroy

Example

Result:


detach

Example

Result:


empty

Example

Result:


hasClass

Example

Result:


html

Example #1 (Set)

Result:

Example #1 (Get)

Result:


prependWith

Example

Result:


prependTo

Example

Result:


removeAttr

Example

Result:


removeClass

Example

Result:


substituteWith

Example

text

Example

unwrap

Unwrap each current node by removing its parent, replacing the parent with its children (i.e. the current node and its siblings).

Note that each node is operated on separately, so when you call unwrap() on a NodeList containing two siblings, two parents will be removed.

Example

Result:


wrap

Wrap the current node or nodes in the given structure.

The wrapping structure can be nested, but should only contain one node on each level (any extra siblings are removed). The outermost node replaces the node operated on, while the node operated on is put into the innermost node.

If called on a NodeList, each of nodes in the list will be separately wrapped. When such a list contains multiple nodes, the argument to wrap() cannot be a NodeList or \DOMNode, since those can be used to wrap a node only once. A string or callable returning a string or a unique NodeList or \DomNode every time can be used in this case.

When a callable is passed, it is called once for each node operated on, passing that node and its index. The callable should return either a string, or a unique NodeList or \DOMNode ever time it is called.

Note that this returns the original node like all other methods, not the (new) node(s) wrapped around it.

Example

Result:


wrapAll

Like wrap(), but when operating on multiple nodes, all of them will be wrapped together in a single instance of the given structure, rather than each of them individually.

Note that the wrapping structure replaces the first node operated on, so if the other nodes operated on are not siblings of the first, they will be moved inside the document.

Example

Result:


wrapInner

Like wrap(), but rather than wrapping the nodes that are being operated on, this wraps their contents.

Example

Result:


Traversal

add

Add additional node(s) to the existing set.

Example

children

Return all children of each element node in the current set.

Example

closest

Return the first element matching the supplied input by traversing up through the ancestors of each node in the current set.

Example

contents

Return all children of each node in the current set.

Example

eq

Return node in the current set at the specified index.

Example

filter

Return nodes in the current set that match the input.

Example

find

Return the decendants of the current set filtered by the selector and optional XPath axes.

Example

first

Return the first node of the current set.

Example

has

Return nodes with decendants of the current set matching the input.

Example

is

Test if nodes from the current set match the input.

Example

last

Return the last node of the current set.

Example

map

Apply a callback to nodes in the current set and return a new NodeList.

Example

following

Return the sibling immediately following each element node in the current set.

Optionally filtered by selector.

Example

followingAll

Return all siblings following each element node in the current set.

Optionally filtered by selector.

Example

followingUntil

Return all siblings following each element node in the current set upto but not including the node matched by $input.

Optionally filtered by input.
Optionally filtered by selector.

Example

not

NodeList not(string|NodeList|\DOMNode|callable $input)

Return element nodes from the current set not matching the input.

Example
$nodes = $doc->find('a');
$missingHrefAttribute = $nodes->not('[href]');

parent

Element|NodeList|null parent([string|NodeList|\DOMNode|callable $selector = null])

Return the immediate parent of each element node in the current set.

Optionally filtered by selector.

Example
$nodes = $doc->find('a');
$parentNodes = $nodes->parent();

parents

NodeList parent([string $selector = null])

Return the ancestors of each element node in the current set.

Optionally filtered by selector.

Example
$nodes = $doc->find('a');
$ancestorDivNodes = $nodes->parents('div');

parentsUntil

NodeList parentsUntil([[string|NodeList|\DOMNode|callable $input, [string|NodeList|\DOMNode|callable $selector = null])

Return the ancestors of each element node in the current set upto but not including the node matched by $selector.

Optionally filtered by input.
Optionally filtered by selector.

Example
$nodes = $doc->find('a');
$ancestorDivNodes = $nodes->parentsUntil('div');

preceding

\DOMNode|null preceding([string|NodeList|\DOMNode|callable $selector = null])

Return the sibling immediately preceding each element node in the current set.

Optionally filtered by selector.

Example
$nodes = $doc->find('a');
$precedingNodes = $nodes->preceding();

precedingAll

NodeList precedingAll([string|NodeList|\DOMNode|callable $selector = null])

Return all siblings preceding each element node in the current set.

Optionally filtered by selector.

Example
$nodes = $doc->find('a');
$precedingAllNodes = $nodes->precedingAll('[anchor]');

precedingUntil

NodeList precedingUntil([[string|NodeList|\DOMNode|callable $input = null], string|NodeList|\DOMNode|callable $selector = null])

Return all siblings preceding each element node in the current set upto but not including the node matched by $input.

Optionally filtered by input.
Optionally filtered by selector.

Example
$nodes = $doc->find('a');
$precedingUntilNodes = $nodes->precedingUntil('.submit');

siblings

NodeList siblings([[string|NodeList|\DOMNode|callable $selector = null])

Return siblings of each element node in the current set.

Optionally filtered by selector.

Example
$nodes = $doc->find('p');
$siblings = $nodes->siblings();

slice

NodeList slice(int $start[, int $end])

Return a subset of the current set based on the start and end indexes.

Example
$nodes = $doc->find('p');
// Return nodes 1 through to 3 as a new NodeList
$slicedNodes = $nodes->slice(1, 3);

Additional Methods

count

int count()
Example
$nodes = $doc->find('p');

echo $nodes->count();

each

self each(callable $function)
Example
$nodes = $doc->find('p');

$nodes->each(function($node){
    echo $node->nodeName . "\n";
});

Licensing

PHP DOM Wrapper is licensed by Andrew Scott under the BSD 3-Clause License, see the LICENSE file for more details.


All versions of php-dom-wrapper with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.0
ext-mbstring Version *
ext-libxml Version *
lib-libxml Version >=2.7.7
symfony/css-selector Version ^5.0 || ^6.0 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package scotteh/php-dom-wrapper contains the following files

Loading the files please wait ....