timgws / cleanhtml
Quickly & Easily clean out HTML text, making sure that only the bare minimum is left behind
dev-master
2016-03-11 04:02 UTC
Requires
- ext-simplexml: *
- ext-xml: *
- ezyang/htmlpurifier: dev-master
Requires (Dev)
- phpunit/phpunit: 4.7.*@dev
This package is auto-updated.
Last update: 2024-11-08 12:02:40 UTC
README
Making HTML clean since late 2012!
Requirements
- PHP 5.2+
- php-xml
How to install
composer require timgws/cleanhtml
How to use
use timgws\CleanHTML\CleanHTML; $tidy = new CleanHTML(); $output = $tidy->clean('<p><strong>I need a shower. I am dirty HTML.</strong>');
$output should now contain:
<h2>I need a shower. I am dirty HTML.</h2>
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
What does it do?
- Removed additional spaces from HTML
- Replaces multiple
<br />
tags with paragraph tags - Removes any
<script>
tags - Renames any
<h1>
tags to<h2>
- Changes
<p><strong>
tags to<h2>
- Replaces
<h2><strong>
with just<h2>
tags - Removes weird
<p><span>
tags - Uses HTML purifier to only allow h1,h2,h3,h4,h5,p,strong,b,ul,ol,li,hr,pre,code tags
- Runs steps 3->7 one more time, just to catch anything that might have missed by allowed tags
- Outputs nice clean HTML \o/