PHP code example of glicer / simply-html

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

    

glicer / simply-html example snippets


// Must point to composer's autoload file.
tents
$html = file_get_contents("index.html");

$dom = new GlHtml($html);

//delete all style tags inside head
$dom->delete('head style');

//prepare a new style tag
$style = '<link href="solver.css" type="text/css" rel="stylesheet"></link>';

//add the new style tag
$dom->get("head")[0]->add($style);

//replace a node
$dom->get("span")[0]->replaceMe("<h1></h1>");

//write result in a new html file
file_put_contents("result.html",$dom->html());

// Must point to composer's autoload file.
tents
$html = file_get_contents("index.html");

$dom = new GlHtml($html);

//array of string sentences
$sentences = $dom->getSentences();

print_r($sentences);

// Must point to composer's autoload file.
tents
$html = file_get_contents("index.html");

$dom = new GlHtml($html);

//array of string url
$links = $dom->getLinks();

print_r($links);


// Must point to composer's autoload file.
$html = file_get_contents("index.html");

$dom = new GlHtml($html);

//array of GlHtmlSummary object
$summary = $dom->getSummary();

echo $summary[0]->getNode()->getText() . ' ' . $summary[0]->getLevel();

/* 
  extract html headings tree
*/
$summaryTree = $dom->getSummaryTree();
bash
php composer.phar install