2017 © Pedro Peláez
 

library simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

image

glicer/simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  • Monday, September 5, 2016
  • by emmanuelroecker
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,278 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 10 Versions
  • 22 % Grown

The README.md

php-simply-html

Scrutinizer Code Quality Build Status Coverage Status SensioLabsInsight Dependency Status, (*1)

Add, delete, modify, read html tags by using css selector., (*2)

Get all text, links, summary inside html file., (*3)

It's working with PHP DOM Extension and Symfony CssSelector, (*4)

Installation

This library can be found on Packagist., (*5)

The recommended way to install is through composer., (*6)

Edit your composer.json and add :, (*7)

{
    "require": {
       "glicer/simply-html": "dev-master"
    }
}

Install dependencies :, (*8)

php composer.phar install

How to modify 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);

//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("

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

How to get all text inside 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);

How to extract html headings (h1,h2,...,h6)?

<?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();

Running Tests

Launch from command line :, (*9)

vendor\bin\phpunit

License MIT

Contact

Authors : Emmanuel ROECKER & Rym BOUCHAGOUR, (*10)

Web Development Blog - http://dev.glicer.com, (*11)

The Versions

05/09 2016

dev-master

9999999-dev https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

05/09 2016

1.1.7

1.1.7.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

24/08 2016

1.1.6

1.1.6.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

17/08 2016

1.1.5

1.1.5.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

17/08 2016

1.1.4

1.1.4.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

03/03 2016

1.1.3

1.1.3.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

05/01 2016

1.1.2

1.1.2.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

02/01 2016

1.1.1

1.1.1.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

02/01 2016

1.1.0

1.1.0.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector

17/03 2015

1.0.0

1.0.0.0 https://github.com/emmanuelroecker/php-simply-html

Simplify add, delete, modify, get nodes in html files by using css selector

  Sources   Download

MIT

The Requires

 

The Development Requires

css xml html selector