PHP code example of elmijo / php-html-dom
1. Go to this page and download the library: Download elmijo/php-html-dom 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/ */
elmijo / php-html-dom example snippets
$dom = new \PHPTools\PHPHtmlDom\PHPHtmlDom;
$dom->importHTML('http://php.net/');
$dom->importHTML('/ruta/del/archivo.txt');
$dom->importHTML('<div id="content-1"><ul><li class="item">item 1</li><li class="item">item 2</li></ul></div>');
if(!!$dom->importHTML('http://php.net/'))
{
...
//Si se logra importar el contenido devuelve TRUE
...
}
$domlist = $dom->e('article');
//o
$domlist = $dom->e('.clase-de-los-elementos');
//o
$domlist = $dom->e('#id-del-elemento');
//o
$domlist = $dom->e('article > div > p:first-child');
$dom = new \PHPTools\PHPHtmlDom\PHPHtmlDom;
if(!!$dom->importHTML('http://php.net/'))
{
var_dump($domlist->count());
$domlist = $dom->e('article');
$element = $domlist->eq(0);
$parentElem = $element->parent();
$find = $domlist->eq(0)->childs->find('p');
$find->each(function($inx,$ele){
echo sprintf("%s : %s","Tiene la clase item",$ele->hasclass('item'));
echo sprintf("%s : %s","Nombre de la Etiqueta",$ele->tagName);
echo sprintf("%s : %s","Texto con Forrmato",$ele->textFormatting);
});
}
json
"...
"elmijo/php-html-dom": "1.0"
...
}