PHPackages                             hk-r/dindent - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hk-r/dindent

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hk-r/dindent
============

HTML indentation library for development and testing.

2.4.0(8y ago)0291BSD-3-ClausePHPPHP &gt;=5.3

Since Apr 16Pushed 8y agoCompare

[ Source](https://github.com/hk-r/dindent)[ Packagist](https://packagist.org/packages/hk-r/dindent)[ Docs](https://github.com/gajus/dindent)[ RSS](/packages/hk-r-dindent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (8)Used By (1)

Dindent
=======

[](#dindent)

[![Build Status](https://camo.githubusercontent.com/a7eb0957a7e739fb037ee4db74a28751a451872d79c37c22fa80f37ce912fb6e/68747470733a2f2f7472617669732d63692e6f72672f67616a75732f64696e64656e742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/gajus/dindent)[![Coverage Status](https://camo.githubusercontent.com/53d959af1746e2cf40d4d4564324562e6891bb971515634e4f7515ade6f65d8c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f67616a75732f64696e64656e742f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/gajus/dindent?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/c744ce56953b4a75f57c25178c8af98c5a7c569f426818a87988149813d935ea/68747470733a2f2f706f7365722e707567782e6f72672f67616a75732f64696e64656e742f76657273696f6e2e706e67)](https://packagist.org/packages/gajus/dindent)[![License](https://camo.githubusercontent.com/02cc8c53764b972caf216d06bc364bde9a3af1318a743b9ef7414ad943b18413/68747470733a2f2f706f7365722e707567782e6f72672f67616a75732f64696e64656e742f6c6963656e73652e706e67)](https://packagist.org/packages/gajus/dindent)

Dindent (aka., "HTML beautifier") will indent HTML for development and testing. Dedicated for those who suffer from reading a template engine produced markup.

Abuse Case
----------

[](#abuse-case)

Dindent will not sanitize or otherwise manipulate your output beyond indentation.

If you are looking to remove malicious code or make sure that your document is standards compliant, consider the following alternatives:

- [HTML Purifier](https://github.com/Exercise/HTMLPurifierBundle)
- [DOMDocument::$formatOutput](http://www.php.net/manual/en/class.domdocument.php)
- [Tidy](http://www.php.net/manual/en/book.tidy.php)

If you need to indent your code in the development environment, beware that earlier mentioned libraries will attempt to fix your markup (that's their primary purpose; indentation is a by-product).

Regex
-----

[](#regex)

There is a [good reason not to use regular expression to parse HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). However, DOM parser will rebuild the whole HTML document. It will add missing tags, close open block tags, or remove anything that's not a valid HTML. This is what Tidy does, DOM, etc. This behavior is undesirable when debugging HTML output. Regex based parser will not rebuild the document. Dindent will only add indentation, without otherwise affecting the markup.

The above is also the reason why [Chrome DevTools](https://developers.google.com/chrome-developer-tools/) is not a direct replacement for Dindent.

Use
---

[](#use)

```
$indenter = new \Gajus\Dindent\Indenter();
$indenter->indent('[..]');
```

In the above example, `[..]` is a placeholder for:

```
>

    console.log('te>
