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>
*/

$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>