PHPackages                             originphp/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. originphp/html

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

originphp/html
==============

OriginPHP Html

2.0.0(5y ago)412.0k↓33.3%4MITPHPPHP &gt;=7.3.0CI failing

Since Oct 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/originphp/html)[ Packagist](https://packagist.org/packages/originphp/html)[ Docs](https://www.originphp.com)[ RSS](/packages/originphp-html/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (10)Used By (4)

Html
====

[](#html)

[![license](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)[![build](https://github.com/originphp/html/workflows/CI/badge.svg)](https://github.com/originphp/html/actions)[![coverage](https://camo.githubusercontent.com/18ae1147bc8384cdb217980516f9696d406dacfd309381c543c5a4901c923eb7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f726967696e7068702f68746d6c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/originphp/html?branch=master)

The Html class provides some useful functions for when working with HTML.

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

[](#installation)

To install this package

```
$ composer require originphp/html

```

Then add to your file

```
use Origin\Html\Html;

```

From Text
---------

[](#from-text)

If you need to convert a text block to html

```
$text = 'div']);
```

To Text
-------

[](#to-text)

You can also convert a HTML string to formatted text

```
$text = Html::toText($html);
```

For example

```
$html = false]);
```

The main difference is headings, tables, code etc are not formatted. The HTML is cleaned up, line breaks are added, and lists are converted. If a list has a sublist then indentation will be added.

Minify
------

[](#minify)

Minify cleans up the spacing, removes comments and thus minifies a HTML string.

```
$minified = Html::minify($html);
```

The following options are supported

- collapseWhitespace: default:true. Collapse whitespace in the text nodes
- conservativeCollapse: default:false. Always collapse whitespace to at least 1 space
- collapseInlineTagWhitespace: default:false. Don't leave any spaces between inline elements.
- minifyJs: default:false minifies inline Javascript (beta)
- minifyCss: default:false minifies inline CSS (beta)

Sanitize
--------

[](#sanitize)

Sanitize enables to only allow certain tags and attributes in a HTML string.

```
$html = Html::sanitize($html,[
    'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
    'p',
    'i', 'em', 'strong', 'b', 'blockquote', 'del',
    'a' => ['href'],
    'ul', 'li', 'ol', 'br',
    'code', 'pre',
    'img' => ['src','alt']]
    );
```

Strip Tags
----------

[](#strip-tags)

To strip selected tags and their content from a HTML string, in other words strip tags that are in a blacklist

```
$html = Html::stripTags($html,['script','iframe','img']);
```

Escape
------

[](#escape)

It is important when displaying user inputted HTML that it is escaped properly for security reasons, see [Cross-site scripting](https://www.google.com/about/appsecurity/learning/xss/) for more information.

```
$escaped = Html::escape($html);
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Recently: every ~28 days

Total

9

Last Release

1961d ago

Major Versions

1.2.2 → 2.0.02021-01-04

PHP version history (3 changes)1.0.0PHP ^7.2.0

1.2.1PHP &gt;=7.2.0

2.0.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e8a821333d9c7b7bc2ad3d164d142f65cd3912dea78033d31f76b0f19ba8a0c?d=identicon)[originphp](/maintainers/originphp)

---

Top Contributors

[![jamielsharief](https://avatars.githubusercontent.com/u/20553479?v=4)](https://github.com/jamielsharief "jamielsharief (42 commits)")

---

Tags

htmlminifycompresssanitizehtml2textstrip\_tagsoriginPHP

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/originphp-html/health.svg)

```
[![Health](https://phpackages.com/badges/originphp-html/health.svg)](https://phpackages.com/packages/originphp-html)
```

###  Alternatives

[ezyang/htmlpurifier

Standards compliant HTML filter written in PHP

3.3k327.6M445](/packages/ezyang-htmlpurifier)[symfony/html-sanitizer

Provides an object-oriented API to sanitize untrusted HTML input for safe insertion into a document's DOM.

27932.2M63](/packages/symfony-html-sanitizer)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

414211.4k](/packages/fitztrev-laravel-html-minify)[mathiasreker/php-svg-optimizer

php-svg-optimizer is a PHP library designed to optimize SVG files by applying various transformations and cleanup operations.

338.9k2](/packages/mathiasreker-php-svg-optimizer)[nochso/html-compress-twig

Twig extension for compressing HTML and inline CSS/Javascript

84468.6k8](/packages/nochso-html-compress-twig)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
