Nobody really wants to do imperative dom manipulation on the back end, but sometimes you have to. Given that you've probably done a lot of dom manipulation in javascript, maybe it would be nice to use the same api on the back end. Use cases for this project include:
- DOM Crawlers
- Integration testing
- Link previews
Via Composer
composer require jclyons52/php-query
$html = <div class="row">
<div class="col-sm-3" id="div-1"> First Div </div>
<div class="col-sm-3" id="div-2"> Second Div </div>
<div class="col-sm-3 third" id="div-3" data-last-value="43" data-hidden="true" data-options='{"name":"John"}'> Third Div </div>
</div>';
$dom = new Jclyons52\PHPQuery\Document($html);
$elements = $dom->querySelector('.col-sm-3');
$element->attr('styles', 'display: block;');
echo $element->attr('styles'); // 'display: block'
echo $element->text(); // 'First Div'
echo $element->hasClass('col-sm-3); // true
$element->css(); // ["color" => "blue", "display" => "none"];
$div3 = $dom->querySelectorAll('.col-sm-3')[2];
$div3->data(); // ["last-value" => 43, "hidden" => true, "options" => '{"name":"John"}']
echo $element->toString(); // '<div class="col-sm-3" id="div-1"> First Div </div>'
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email jclyons52@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.