A lightweight package for xpath manipulations., (*2)
composer require h0gar/xpath *
HTML, (*5)
$html = file_get_contents('page.html'); $doc = new \H0gar\Xpath\Doc($html, 'html');
XML, (*6)
$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();
Please submit all issues and pull requests to the h0gar/xpath repository., (*14)
Open-sourced software licensed under the MIT license, (*15)