Download the PHP package lostcause/php-htmltruncator without Composer

On this page you can find all versions of the php package lostcause/php-htmltruncator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-htmltruncator

PHP HTML Truncator

This is a PHP port of the html_truncator gem.

It will cleanly truncate HTML content, appending an ellipsis or other marker in the most suitable place. There is optional support for php-html5lib if parsing of non-well-formed HTML5 is required. This is because PHP's DOMDocument->loadHTML (or the underlying libxml) doesn't recognize HTML5.

During the truncation process the HTML will be loaded into a DOMDocument. This can be relatively slow and memory hungry, so you may want to cache the truncated output.

How to use it

The HtmlTruncator\Truncator class has only one static method, truncate, with 3 arguments:

And a static attribute, $ellipsable_tags, which lists the tags that can contain the ellipsis (by default: p ol ul li div header article nav section footer aside dd dt dl).

Examples

A simple example:

Truncator::truncate("<p>Lorem ipsum dolor sit amet.</p>", 3);
# => "<p>Lorem ipsum dolor…</p>"

If the text is too short to be truncated, it won't be modified:

Truncator::truncate("<p>Lorem ipsum dolor sit amet.</p>", 5);
# => "<p>Lorem ipsum dolor sit amet.</p>"

If you prefer, you can have the length in characters instead of words:

Truncator::truncate("<p>Lorem ipsum dolor sit amet.</p>", 12, array('length_in_chars' => true));
# => "<p>Lorem ipsum …</p>"

You can customize the ellipsis:

Truncator::truncate("<p>Lorem ipsum dolor sit amet.</p>", 3, " (truncated)");
# => "<p>Lorem ipsum dolor (truncated)</p>"

And even have HTML in the ellipsis:

Truncator::truncate("<p>Lorem ipsum dolor sit amet.</p>", 3, '<a href="/more-to-read">...</a>');
# => "<p>Lorem ipsum dolor<a href="/more-to-read">...</a></p>"

The ellipsis is put at the right place, inside <p>, but not <i>:

Truncator::truncate("<p><i>Lorem ipsum dolor sit amet.</i></p>", 3);
# => "<p><i>Lorem ipsum dolor</i>…</p>"

You can indicate that a tag can contain the ellipsis by adding it to the ellipsable_tags:

Truncator::$ellipsable_tags[] = "blockquote";
Truncator::truncate("<blockquote>Lorem ipsum dolor sit amet.</blockquote>", 3);
# => "<blockquote>Lorem ipsum dolor…</blockquote>"

Credits

This PHP port is entirely based on Bruno Michel's excellent rubygem, any bugs introduced are likely mine.

Ported 2013-07-04 by Jude Venn [email protected], released under the MIT license


All versions of php-htmltruncator with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
electrolinux/php-html5lib Version dev-master
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lostcause/php-htmltruncator contains the following files

Loading the files please wait ....