1. Go to this page and download the library: Download ryangittings/didom 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/ */
ryangittings / didom example snippets
use DiDom\Document;
$document = new Document('http://www.news.com/', true);
$posts = $document->find('.post');
foreach($posts as $post) {
echo $post->text(), "\n";
}
// the first parameter is a string with HTML
$document = new Document($html);
// or URL
$document = new Document('http://www.example.com/', true);
$document = new Document();
$document->loadHtml($html);
$document->loadHtmlFile('http://www.example.com/');
if ($document->has('.post')) {
$elements = $document->find('.post');
// code
}
if (count($elements = $document->find('.post')) > 0) {
// code
}
// all links
$document->find('a');
// any element with id = "foo" and "bar" class
$document->find('#foo.bar');
// any element with attribute "name"
$document->find('[name]');
// the same as
$document->find('*[name]');
// input field with the name "foo"
$document->find('input[name=foo]');
$document->find('input[name=\'bar\']');
$document->find('input[name="baz"]');
// any element that has an attribute starting with "data-" and the value "foo"
$document->find('*[^data-=foo]');
// all links starting with https
$document->find('a[href^=https]');
// all images with the extension png
$document->find('img[src$=png]');
// all links containing the string "example.com"
$document->find('a[href*=example.com]');
// text of the links with "foo" class
$document->find('a.foo::text');
// address and title of all the fields with "bar" class
$document->find('a.bar::attr(href|title)');
$document = new Document();
$document->preserveWhiteSpace();
$document->loadXml($xml);
// prints the number of links in the document
echo $document->count('a');
// prints the number of items in the list
echo $document->first('ul')->count('li');
$element->matches('div#content');
// strict match
// returns true if the element is a div with id equals content and nothing else
// if the element has any other attributes the method returns false
$element->matches('div#content', true);
$element->isElementNode();
$element->isTextNode();
$element->isCommentNode();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.