jclyons52/php-query

jQuery / javascript api for html document manipulation in php

1.3.2 2016-10-23 22:07 UTC

This package is not auto-updated.

Last update: 2024-11-05 21:25:12 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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:

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.