Download the PHP package valhook/dparse without Composer
On this page you can find all versions of the php package valhook/dparse. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dparse
dParse
dParse is a strong jQuery-like HTML/XML parser written in PHP. I initiated this project when I realized that the current parsers (Simple HTML DOM, Ganon, etc ...) that we can find on the Internet could be improved. So I decided to create a PHP parser that is better by improving the following points:
- Speed
- Features
- Flexibility
- Memory use
Installation
When you are in your root directory, you can just run this command to add this package on your app
Or add this package to your composer.json
Usage
The information below explains how to use the different functionalities of dParse.
Creating the DOM
- $source can be a remote URL, a raw HTML/XML source code or a local filepath.
- $args is an optional parameter that is an array specifying advanced options. Below are the default args.
Or just retrieving the raw contents
Raw content and DOM level operations
The DOM object provides the following functions
Getting DOM nodes
DOM nodes/tags are queried with CSS selectors like jQuery
The MetaNode Object
- The CSS-like selecting query returns a MetaNode object which is a set of different nodes.
$dom('div');
will give you a MetaNode object contaning n Node Objects
Before we see how interact with the nodes within the MetaNode Object we will see all the MetaNode Object operations.
Versatility of the MetaNode
- A MetaNode is an interface between you and the nodes of the DOM you requested to handle multi-nodes operations.
-
If you have multiple nodes, you can pass the MetaNode Node-level functions to all of its nodes, and it will return a result set in an array containing the response from all the nodes.
-
However if your MetaNode contains only one node, you can directly use your MetaNode as a single node and call its different functions that are listed below.
-
But if you do not want to use this versatility, or if you don't know how many nodes you have, you can iterate through the MetaNode with a
foreach
even though it contains only one node. - You can pass any Node-level function to your MetaNode. Node-level functions are listed right below.
The Node Object
- A node is an HTML tag.
<a ...>Foo</a>
is a node. - The node object can be used to extract or modify its contents.
- If a modification is made it will directly update the whole DOM.
Getters
The getters are for the most part the same as jQuery's.
CSS Sub-querying
- Just like jQuery, you can perform CSS queries from a node instead of from the whole DOM.
- If you apply any of the CSS sub-querying functions on a MetaNode, you will get a MetaNode that is the union of the result of the same query applied to each node.
Type of selectors
- No selector: The method takes no parameter
- Selector: The method takes a CSS Selector parameter
- SmartSelector: The method takes a parameter that can be:
- A CSS Selector
- A MetaNode or Node (ex: parentsUntil($node)) will return all the parents until one matches the specified node or is part of the MetaNode
- Occasionnaly if that makes sense: An INT (ex: parentsUntil(2)) will return the first 2 parents
Methods
Setters
- Just like jQuery, they modify directly the node or metanode, all other instances of this node, and the DOM.
- They are not fully finished, so far I have only made four methods
That's it for the Node and Meta Nodes !
Logger
- dParse bundles a logger for debugging purposes.
- The logger is disabled by default but you can enable it when creating the DOM (it is on the of specifiable arguments) or later via the Logger API
Methods
Example of logs
Practical Examples using dParse
Getting the headlines of a Wikipedia article
outputs:
Getting the video search results & links on youtube
outputs: