Download the PHP package gymadarasz/xparser without Composer
On this page you can find all versions of the php package gymadarasz/xparser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package xparser
XParser
XParser is a very fast XHTML DOM Parser and easy to use.
If you like the jQuery style DOM selection at the PHP backend side or you like simple_html_dom or Ganon you will love this smart library!
Why you sould use it?
- benchmark:
and:
- PHP 5.6
- Composer & PSR-4 Support
- Unit testing via Minitest
- PHP-Quality testing via SensioLabsInsight
Install via Composer
$ composer require gymadarasz/xparser
Or download latest version
Usage
Validation
The validation is not too quick process and you don't have to use it every single html loading and parsing but if you aren't sure that your html is valid, you can check it before use:
Note: Be carefull!
Technically when you make a query which try to find something recursion in html struct the regex search time exponentially improve but If you try to find an exact element it seem to be very fast. So this lib fast incase if you know which is the element (or a few of elements) what you looking for and these elements aren't too deep in DOM tree in a recursion.
We never can know in the recurions before try to proccess it, so I had to make a recursion detect in the element search function. It will working until get the deeply process as a class variable in XNode. So if you need deeper searching as default at private static $maxRecursionInStartegy = 8;
you can modify it but be carefull!
Get count of elements
When you can not know how many element will in your query incase I created a getCount
function which relatively fast and give you how much element are in your selection:
Get parent element:
Other facilities
Symfony CSS-Selector implemented:
If you want to use more css selection in your queries more option e.g. '>' child selection and 'nth-child' or selection by attribute etc. it's possible via Symfony CSS-Selector DOMDocument and XPath.
Note: My goal is not to make a better CSS selection than e.g symphony. I want to make a realy fast html reader and/or manipulator lib for php, the css selection is just an 'extra' in this lib. If you have any idea how it will better please leave an issue on github.