Download the PHP package amsify42/php-domfinder without Composer
On this page you can find all versions of the php package amsify42/php-domfinder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amsify42/php-domfinder
More information about amsify42/php-domfinder
Files in amsify42/php-domfinder
Package php-domfinder
Short Description PHP package for searching document object model efficiently and with more readable way.
License MIT
Informations about the package php-domfinder
PHP DOM Finder
PHP package for searching document object model efficiently and with more readable way.
Installation
Table of Contents
- Loading Source
- Important Notes
- Meta Tags
- Elements
- Element Class
- Element Id
- Element Attribute
- Regex Extraction
- Element Methods
- Multi Level Finder
1. Loading Source
File
HTML
XML
URL
For HTML
For XML
Using helper method
Note: Make sure you pass true
as 3rd parameter to constructor/helper method or 2nd parameter to load method for loading content from URL.
2. Important Notes
1. DOMDocument
Amsify42\DOMFinder\DOMFinder
class uses Amsify42\DOMFinder\DOM\Document
which extends PHP pre defined class DOMDocument. You can use all the methods of DOMDocument
using this instance
Example:
2. DomXPath
Amsify42\DOMFinder\DOMFinder
class uses PHP pre defined class DomXPath
for querying document. If you want to use all the methods of DomXPath, you can use this instance
Example:
3. DOMElement
All the element results you get after querying document will be of type Amsify42\DOMFinder\DOM\Element
which extends PHP pre defined class DOMElement.
You can use all the methods of DOMElement
from all the element items.
Example:
Most importantly, whenever you try to get the first or particular key element by index, it will either return NULL
or element of type Amsify42\DOMFinder\DOM\Element
.
Examples:
3. Meta Tags
After source has been loaded, you can use these meta tags related methods.
To get specific meta tag value
By default it takes content attribute value from meta element, to get value from other attribute, pass 3rd parameter
4. Elements
To get specific elements from DOM
To get first element
To get the element by index position
5. Element Class
Equals
Find all elements by class name
Find first element by class
Find all div tag element by class
Find first div tag element by class
For getting element by its key position
Like
Find all elements contains class
Find first element contains class
Find all div tag element contains class
Find first div tag element contains class
For getting element by its key position
6. Element Id
Equals
Find all elements by id
Find first element by id
Find all div tag element by id
Find first div tag element by id
Like
Find all elements contains id
Find first element contains id
Find all div tag element contains id
Find first div tag element contains id
For getting element by its key position
7. Element Attribute
Equals
Find all elements by attribute
Find first element by attribute
Find all div tag element by attribute
Find first div tag element by attribute
For getting element by its key position
Like
Find all elements contains attribute
Find first element contains attribute
Find all div tag element contains attribute
Find first div tag element contains attribute
For getting element by its key position
8. Regex Extraction
To extract particular item from html, consider this sample html
For extracting multiple instances of data by regex, pass 2nd parameter as true
You can also pass multiple regex as array for multi level check and extraction
9. Element methods
These are the methods you can use at element level
For getting outer and inner HTML of element, you can use these methods
Outer html will print
Inner html will print
10. Multi Level Finder
This section is to demonstrate how the dom finder works at multi level.
Simple
The above query is same as DomXPath
You will get all the ul elements
Element Level
This approach actually creates DOMFinder
instance at each element level when you try to do query.