Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timgws/cleanhtml
A `Clean` function that will remove tables, any Javascript or other non-friendly items that you might not want to see from user submitted HTML.
https://github.com/timgws/cleanhtml
Last synced: 2 months ago
JSON representation
A `Clean` function that will remove tables, any Javascript or other non-friendly items that you might not want to see from user submitted HTML.
- Host: GitHub
- URL: https://github.com/timgws/cleanhtml
- Owner: timgws
- Created: 2013-06-13T06:09:11.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-03-11T04:02:12.000Z (almost 9 years ago)
- Last Synced: 2024-04-17T05:36:36.231Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 36.1 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CleanHTML
[![Test Coverage](https://codeclimate.com/github/timgws/CleanHTML/badges/coverage.svg)](https://codeclimate.com/github/timgws/CleanHTML/coverage)
[![Code Climate](https://codeclimate.com/github/timgws/CleanHTML/badges/gpa.svg)](https://codeclimate.com/github/timgws/CleanHTML)Making HTML clean since late 2012!
## Requirements
* PHP 5.2+
* php-xml## How to install
```
composer require timgws/cleanhtml
```## How to use
```phpuse timgws\CleanHTML\CleanHTML;
$tidy = new CleanHTML();
$output = $tidy->clean('I need a shower. I am dirty HTML.');
```$output should now contain:
```htmlI need a shower. I am dirty HTML.
```Using the Clean function will remove tables, any Javascript or other non-friendly items that
you might not want to see from user submitted HTML.If you want to see some examples, the best place to look would be [some of the CleanHTML test](https://github.com/timgws/CleanHTML/blob/master/tests/CleanHTMLTest.php)
## What does it do?
1. Removed additional spaces from HTML
2. Replaces multiple ``
`` tags with paragraph tags
3. Removes any ```` tags
4. Renames any ``<h1>`` tags to ``<h2>``
5. Changes ``<p><strong>`` tags to ``<h2>``
6. Replaces ``<h2><strong>`` with just ``<h2>`` tags
7. Removes weird ``<p><span>`` tags
8. Uses HTML purifier to only allow h1,h2,h3,h4,h5,p,strong,b,ul,ol,li,hr,pre,code tags
9. Runs steps 3->7 one more time, just to catch anything that might have missed by allowed tags
10. Outputs nice clean HTML \o/