PHP code example of mistralys / simple_html_dom

1. Go to this page and download the library: Download mistralys/simple_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/ */

    

mistralys / simple_html_dom example snippets


use SimpleHtmlDom\Parser;

$html = new Parser('<ul><li class="active">One</li><li>Two</li></ul>');

// Find by CSS selector
$active = $html->find('li.active', 0);
echo $active->plaintext; // "One"

// Modify and output
$active->class = 'done';
echo $html->save(); // <ul><li class="done">One</li><li>Two</li></ul>

$html = str_get_html('<p>Hello <b>World</b></p>');
echo $html->find('b', 0)->plaintext; // "World"