PHP code example of mathsgod / p-query
1. Go to this page and download the library: Download mathsgod/p-query library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mathsgod / p-query example snippets
$p = p('<div class="container">
<div class="hello">Hello</div>
</div>');
$p->find(".hello")->text("abc");
echo $p;
/* output
<div class="container">
<div class="hello">abc</div>
</div>
*/
$p = p('<ul>
<li class="active">One</li>
<li>Two</li>
<li id="last">Three</li>
</ul>');
$p->find("li.active")->text("First");
$p->find("#last")->text("Last");
$p->find("li:nth-child(2)")->text("Middle");
echo $p;
$div = new HTMLDivElement();
$div->classList->add("container");
$div->innerText = "Hello world!";
$div->style->color = "red";
echo $div; // <div class="container" style="color: red">Hello world!</div>
$div = new HTMLDivElement();
$p = new HTMLParagraphElement();
$div->append($p);
echo $div; // <div><p></p></div>
$div = new HTMLDivElement();
$div->append("Some text");
echo $div; // <div>Some text</div>
$div = new HTMLDivElement();
$p = new HTMLParagraphElement();
$div->append("Some text", $p);
echo $div; // <div>Some text<p></p></div>
$p = P\Query::ParseFile("path/to/file.html");
echo $p->find("title")->text();
$p = p('<button>Click me</button>');
$p->on("click", function (P\Event $e) {
echo "Clicked!";
});
$p->trigger("click");