Add, delete, modify, read html tags by using css selector.
Get all text, links, summary inside html file.
It's working with PHP DOM Extension and Symfony CssSelector
This library can be found on Packagist.
The recommended way to install is through composer.
Edit your composer.json
and add :
{
"require": {
"glicer/simply-html": "dev-master"
}
}
Install dependencies :
php composer.phar install
// Must point to composer's autoload file.
require 'vendor/autoload.php';
use GlHtml\GlHtml;
//read index.html contents
$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.
require 'vendor/autoload.php';
use GlHtml\GlHtml;
//read index.html contents
$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.
require 'vendor/autoload.php';
use GlHtml\GlHtml;
//read index.html contents
$html = file_get_contents("index.html");
$dom = new GlHtml($html);
//array of string url
$links = $dom->getLinks();
print_r($links);
<?php
// Must point to composer's autoload file.
require 'vendor/autoload.php';
use GlHtml\GlHtml;
//read index.html contents
$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();
Launch from command line :
vendor\bin\phpunit
Authors : Emmanuel ROECKER & Rym BOUCHAGOUR