Download the PHP package md-php/html-truncation without Composer
On this page you can find all versions of the php package md-php/html-truncation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download md-php/html-truncation
More information about md-php/html-truncation
Files in md-php/html-truncation
Package html-truncation
Short Description Provides contract and implementation to truncate HTML code
License MIT
Homepage https://development.md.land/php/md.html.truncation
Informations about the package html-truncation
md-php/html-truncation
md-php/html-truncation is a PHP component that provides contract and implementation to truncate HTML code.
Powered on top of libxml, dom and mbstring builtin PHP extensions.
Text truncation is the process of shortening a piece of text by cutting it off after a certain length,
typically adding an ellipsis ... or another indicator to show that the content has been clipped.
It's useful to create snippets showing only relevant context around a keyword and especially useful to limit content of items in list, for example: generic entry content in admin list, blog articles content and so on.
Architecture overview
Features
- Modern. SOLID & PSR compatible / linted with strict PHPStan and Psalm
- Fast. Recursion-free algorithm
- Memory-efficient. Supports huge documents with nesting up to 100,000 elements (optionally)
- Fresh. Created in 2026, supports latest PHP versions (7.1+ and 8.0+)
Install
Usage
Read documentation for more examples.
Integration with Twig
Take a look for a md-php/bridge-twig-html-truncation component that provides additional Twig filter and function to truncate HTML code, like:
or
Documentation
Read documentation with examples: https://development.md.land/php/md-html-truncation/
Development
Initial setup:
Run checks (Psalm + PHPStan + PHPUnit):
Validate files:
Comparison with other solutions
- md-php/html-truncation (THIS)
- Method: libxml ✅
- Stars: N/A
- Installs: N/A
- Status: Last update: 2026-03-25
- Features: (see features)
- PHP version:
^7.1or^8.0✅
- urodoz/truncate-html
- Method: regular expression ❗
- Stars: 21
- Installs: 287,129
- Status:
Last update: 2014-05-25 ❗
Abandoned (De-facto): No updates, no activity on issues. ❗ - PHP version:
>=5.3❗ - Cons:
- Coupled to Twig component ❗️
- bluetel/twig-truncate-extension
- Method: libxml ✅
- Stars: 11
- Installs: 97,376
- Status:
Last update: 2016-01-19 ❗
Abandoned (De-facto): No updates, no activity on issues. ❗ - PHP version:
>=5.3❗ - Cons:
- issues in master branch ❗
- dumps result only as HTML as full document, no fragment support.
- recursion method ❗
- Coupled to Twig component ❗
- judev/php-htmltruncator
- Method: libxml ✅
- Stars: 29
- Installs: 271,305
- Status:
Last update: 2019-11-19 ❗
Abandoned (no updates, no activity on issues) ❗ - PHP version:
>=5.6❗ - Cons
- One class per file principle violation ❗️
- dzango/TwigTruncateExtension
- Method: regular expression ❗️
- Stars: 13
- Installs: 236,921
- Status:
Last update: 2017-12-02 ❗️
Abandoned (no updates, no activity on issues) ❗ - PHP version:
>=5.6❗ - Pros:
- Adjust cut off in the middle of the word ✅
- Cons:
- One class per file principle violation ❗️
- Coupled to Twig component ❗️
Roadmap
- add cut off in the middle of the word adjustment
- add feature to truncate text by the words count
- add feature to exclude elements from text truncation
- add benchmarks
- simplify Dockerfile
Changelog
License (MIT)
All versions of html-truncation with dependencies
ext-mbstring Version *
ext-dom Version *
php Version ^7.1 || ^8.0
symfony/polyfill-php83 Version ^1.30