PHP code example of pejman / dom-parser
1. Go to this page and download the library: Download pejman/dom-parser 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/ */
pejman / dom-parser example snippets
e( '<div><div class="test">ss<span class="aa">innnerssss</span><span class="aa">innnnn</span></div></div><div class="test1">eee</div>');
dump( $p->document );
$element = $p->find(".test",0);
$element->next;
$element->next();
$element->prev;
$element->prev();
$element->parent;
$element->parent();
//all childs
$element->children();
//first child
$element->children(0);
//all attributes
$element->attrs;
//find in tag
$element->find("span");
//set attr
$element->attr( $key, $value );
//set attr
$element->href='test';
//get attr
$element->href;
$element->getElementById("test");
$element->getElementByTagName("span");
$element->getElementsByTagName("span");
$element->html();
$element->text();
$element->outerHtml();
//remove element
$element->remove();
//update html
$element->html('ddd');
//get html
$element->html();
$element->html;
e( '<div id="test"><div class="test"><span>aaa</span>bbb<span>ccc</span></div></div><div class="test1">eee</div>');
pq("#test span")->each(function( $elm ) {
echo pq( $elm )->html()."\n";
});
print_r( pq("#test")->next()->attr('class') );
echo "\n";
pq("#test")->addClass("added-class");
echo pq("#test")->outerHtml();
echo "\n";
pq("#test")->removeClass("added-class");
echo pq("#test")->outerHtml();
echo "\n";
pq("#test")->addClass("added-class");
echo pq("#test")->outerHtml();
echo "\n";