Download the PHP package ryangittings/didom without Composer

On this page you can find all versions of the php package ryangittings/didom. 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 didom

DiDOM

DiDOM - simple and fast HTML parser.

Contents

Installation

To install DiDOM run the command:

composer require imangazaliev/didom

Quick start

Creating new document

DiDom allows to load HTML in several ways:

With constructor

The second parameter specifies if you need to load file. Default is false.

With separate methods

There are two methods available for loading XML: loadXml and loadXmlFile.

These methods accept additional options:

Search for elements

DiDOM accepts CSS selector or XPath as an expression for search. You need to path expression as the first parameter, and specify its type in the second one (default type is Query::TYPE_CSS):

With method find():

If the elements that match a given expression are found, then method returns an array of instances of DiDom\Element, otherwise - an empty array. You could also get an array of DOMElement objects. To get this, pass false as the third parameter.

With magic method __invoke():
With method xpath():

You can do search inside an element:

Verify if element exists

To verify if element exist use has() method:

If you need to check if element exist and then get it:

but it would be faster like this:

because in the first case it makes two requests.

Supported selectors

DiDom supports search by:

Output

Getting HTML

With method html():
Casting to string:
Formatting HTML output

An element does not have format() method, so if you need to output formatted HTML of the element, then first you have to convert it to a document:

Inner HTML

Document does not have the method innerHtml(), therefore, if you need to get inner HTML of a document, convert it into an element first:

Getting XML

Getting content

Creating a new element

Creating an instance of the class

First parameter is a name of an attribute, the second one is its value (optional), the third one is element attributes (optional).

An example of creating an element with attributes:

An element can be created from an instance of the class DOMElement:

Using the method createElement

Getting the name of an element

Getting parent element

Getting sibling elements

Getting the child elements

Getting document

Working with element attributes

Creating/updating an attribute

With method setAttribute:
With method attr:
With magic method __set:

Getting value of an attribute

With method getAttribute:
With method attr:
With magic method __get:

Returns null if attribute is not found.

Verify if attribute exists

With method hasAttribute:
With magic method __isset:

Removing attribute:

With method removeAttribute:
With magic method __unset:

Comparing elements

Appending child elements

Adding a child element

Replacing element

Removing element

Working with cache

Cache is an array of XPath expressions, that were converted from CSS.

Getting from cache

Cache setting

Miscellaneous

preserveWhiteSpace

By default, whitespace preserving is disabled.

You can enable the preserveWhiteSpace option before loading the document:

count

The count () method counts children that match the selector:

matches

Returns true if the node matches the selector:

isElementNode

Checks whether an element is an element (DOMElement):

isTextNode

Checks whether an element is a text node (DOMText):

isCommentNode

Checks whether the element is a comment (DOMComment):

Comparison with other parsers

Comparison with other parsers


All versions of didom with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
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 ryangittings/didom contains the following files

Loading the files please wait ....