hugsbrugs / php-xpath
PHP XPath Utilities
Installs: 461
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Language:HTML
Requires
- hugsbrugs/php-http: dev-master
This package is auto-updated.
Last update: 2024-12-18 10:13:56 UTC
README
This librairy provides utilities function to ease xpath manipulation
Install
Install package with composer
composer require hugsbrugs/php-xpath
In your PHP code, load librairy
require_once __DIR__ . '/../vendor/autoload.php'; use Hug\Xpath\Xpath as Xpath;
Usage
Extracts all elements matching query
Xpath::extract_all($html, $query = '//a');
Extracts first element matching query
Xpath::extract_first($html, $query = '//body//h3');
Extracts body of HTML document
Xpath::get_body($html);
Replaces body of HTML document
Xpath::replace_body($html, $new_body = '<div>Hello World !</div>');
XPath fails at extracting html tags style attributes content so this function makes it !
Xpath::extract_style($html, $query = '//body//div[@class="inscriptionadsl"]', $style_property = 'height');
Extract first iframe from a webpage matching a given domain name
Xpath::extract_iframe($html, $domain = 'hugo.maugey.fr');
Unit Tests
phpunit --bootstrap vendor/autoload.php tests
Author
Hugo Maugey visit my website ;)