h0gar / xpath
Installs: 1 437
Dependents: 3
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 2
Open Issues: 0
This package is not auto-updated.
Last update: 2024-12-21 16:20:44 UTC
README
#Xpath
A lightweight package for xpath manipulations.
- Installation
- Usage
- Access a node
- Access multiple nodes
- Navigation
- Get a node inner html
- Get a node inner text
- Get an attribute
- \DOMElement and \DOMXpath
composer require h0gar/xpath *
HTML
$html = file_get_contents('page.html');
$doc = new \H0gar\Xpath\Doc($html, 'html');
XML
$xml = file_get_contents('page.xml');
$doc = new \H0gar\Xpath\Doc($xml, 'xml');
$item = $doc->item('/html/body/div[1]/div/div[2]/ul/li[0]');
#or
$item = $doc->item('/html/body/div[1]')->item('div/div[2]/ul/li', 1);
$items = $doc->items('/html/body/div[1]/div/div[2]/ul/li');
foreach($items as $item)
//...
$next = $item->next();
$prev = $item->prev();
$parent = $item->parent();
$html = $item->html();
#or
$html = $doc->html('/html/body/div[1]/div/div[2]/ul/li[0]');
#or
$html = $doc->html('/html/body/div[1]/div/div[2]/ul/li', 1);
$text = $item->text();
#or
$text = $doc->text('/html/body/div[1]/div/div[2]/ul/li[0]');
#or
$text = $doc->text('/html/body/div[1]/div/div[2]/ul/li', 1);
$href = $item->attr('href');
$domelement = $item->getNode();
$domxpath = $item->getXpath();
##Contributing
Please submit all issues and pull requests to the h0gar/xpath repository.
##License
Open-sourced software licensed under the MIT license