sunra/html_to_text

There is no license information available for the latest version (dev-master) of this package.

Working horse HTML to text convertor for PHP. Years of finding right choice

dev-master 2015-12-13 13:58 UTC

This package is auto-updated.

Last update: 2024-11-14 04:23:47 UTC


README

Convert html to text, filter html tags, purify html. Best and most advanced html to text conversion library for php.

Used Htmlpurifier https://github.com/ezyang/htmlpurifier

Install

Add

"ezyang/htmlpurifier": "dev-master",
"sunra/html_to_text": "dev-master"

to required section in you composer.json

Use

// Total remove tags. br converted to new lines
$plain_text = \Sunra\HtmlToText\HtmlToText::plain_text( $html );

// removed all tags but safest 'br,b,strong,li,ol,ul'
$safe_html = \Sunra\HtmlToText\HtmlToText::safe_html( $html );

// remove unsafe code (XSS attacks) and heals html - close tags etc
$purified_html = \Sunra\HtmlToText\HtmlToText::purify( $html );

// Remove all tags but allowed (coma separated - for example 'br,b')
$purified_html = \Sunra\HtmlToText\HtmlToText::filter( $html, $allowed_tags );