jclyons52 / php-query
jQuery / javascript api for html document manipulation in php
1.3.2
2016-10-23 22:07 UTC
Requires
- php: ~5.5|~7.0
- symfony/css-selector: ^2.8
Requires (Dev)
- phpunit/phpunit: 4.*
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-11-19 21:37:34 UTC
README
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
Install
Via Composer
composer require jclyons52/php-query
Usage
$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>'
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email jclyons52@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.