PHPackages                             vrijdagdigital/php-simply-html - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. vrijdagdigital/php-simply-html

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

vrijdagdigital/php-simply-html
==============================

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

1.0.0(3y ago)0589MITPHPPHP &gt;=5.5

Since May 8Pushed 3y agoCompare

[ Source](https://github.com/vrijdagdigital/php-simply-html)[ Packagist](https://packagist.org/packages/vrijdagdigital/php-simply-html)[ Docs](https://github.com/emmanuelroecker/php-simply-html)[ RSS](/packages/vrijdagdigital-php-simply-html/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

php-simply-html
===============

[](#php-simply-html)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ce4268ed3f1ea670dbb42e043b63f97a56d08791c066d53cf7442a875c39a8ee/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656d6d616e75656c726f65636b65722f7068702d73696d706c792d68746d6c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/emmanuelroecker/php-simply-html/?branch=master)[![Build Status](https://camo.githubusercontent.com/a76314d871cd1219e03928cf32f1a76126f15a2c2e503921bde52c339de9848c/68747470733a2f2f7472617669732d63692e6f72672f656d6d616e75656c726f65636b65722f7068702d73696d706c792d68746d6c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/emmanuelroecker/php-simply-html)[![Coverage Status](https://camo.githubusercontent.com/24cfb5a7ba0f17479f9d3f17dd18784194675976936e1d727e084d8263fd5d4c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f656d6d616e75656c726f65636b65722f7068702d73696d706c792d68746d6c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/emmanuelroecker/php-simply-html?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/c69d6729327a44db3ae13fdfc24052ef784a4e5d56fd8dfcdce44eeced240417/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66326636643566652d363333612d343331382d393133362d6432616265616636313431392f6d696e692e706e67)](https://insight.sensiolabs.com/projects/f2f6d5fe-633a-4318-9136-d2abeaf61419)[![Dependency Status](https://camo.githubusercontent.com/8443bc3c41f93dbbd71d30079d46a44eb0804cd741974af62fed6c3a615e4002/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3536383136306330656234663437303033303030303230632f62616467652e7376673f7374796c653d666c61742d737175617265)](https://www.versioneye.com/user/projects/568160c0eb4f47003000020c)

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](http://php.net/manual/en/book.dom.php) and [Symfony CssSelector](http://symfony.com/doc/current/components/css_selector.html)

Installation
------------

[](#installation)

This library can be found on [Packagist](https://packagist.org/packages/glicer/simply-html).

The recommended way to install is through [composer](http://getcomposer.org).

Edit your `composer.json` and add :

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

Install dependencies :

```
php composer.phar install
```

How to modify html ?
--------------------

[](#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 = '';

//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 ?
---------------------------------

[](#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);
```

How to get all links inside html ?
----------------------------------

[](#how-to-get-all-links-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 url
$links = $dom->getLinks();

print_r($links);
```

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

[](#how-to-extract-html-headings-h1h2h6)

```
