Download the PHP package imangazaliev/didom without Composer

On this page you can find all versions of the php package imangazaliev/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?
imangazaliev/didom
Rate from 1 - 5
Rated 5.00 based on 1 reviews

Informations about the package didom

DiDOM

Build Status Total Downloads Latest Stable Version License

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.

Signature:

$string - an HTML or XML string or a file path.

$isFile - indicates that the first parameter is a path to a file.

$encoding - the document encoding.

$type - the document type (HTML - Document::TYPE_HTML, XML - Document::TYPE_XML).

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():

Warning: using this method is undesirable because it may be removed in the future.

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 queries.

Search in element

Methods find(), first(), xpath(), has(), count() are available in Element too.

Example:

Method findInDocument()

If you change, replace, or remove an element that was found in another element, the document will not be changed. This happens because method find() of Element class (a, respectively, the first () and xpath methods) creates a new document to search.

To search for elements in the source document, you must use the methods findInDocument() and firstInDocument():

Warning: methods findInDocument() and firstInDocument() work only for elements, which belong to a document, and for elements created via new Element(...). If an element does not belong to a document, LogicException will be thrown;

Supported selectors

DiDom supports search by:

Changing content

Change inner HTML

Change inner XML

Change value (as plain text)

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 owner 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

Waning: you can replace only those elements that were found directly in the document:

More about this in section Search for elements.

Removing element

Warning: you can remove only those elements that were found directly in the document:

More about this in section Search for elements.

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 >=7.2
ext-dom Version *
ext-iconv Version *
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 imangazaliev/didom contains the following files

Loading the files please wait ....