mrcgrtz / php-shorten

💬 Provides additional truncation functions in PHP.

Home Page:https://packagist.org/packages/marcgoertz/shorten

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shorten

Provides additional truncation functions in PHP.

Test Coverage Status Packagist PHP Version Support Packagist Downloads Packagist Stars MIT License

Installation

I recommend using Composer for installing and using Shorten:

composer require marcgoertz/shorten

Of course you can also just require it in your scripts directly.

Usage

<?php

use Marcgoertz\Shorten\Shorten;

$shorten = new Shorten();
print $shorten->truncateMarkup('<a href="https://example.com/">Go to example site</a>', 10);
?>

Output:

<a href="https://example.com/">Go to exam</a>…

Functions

truncateMarkup(
    string $markup,
    int $length = 400,
    string $appendix = '…',
    bool $appendixInside = false,
    bool $wordsafe = false
): string
  • String $markup: Text containing markup
  • Integer $length: Maximum length of truncated text (default: 400)
  • String $appendix: Text added after truncated text (default: '…')
  • Boolean $appendixInside: Add appendix to last content in tags, increases $length by 1 (default: false)
  • Boolean $wordsafe: Wordsafe truncation (default: false)
  • String $delimiter: Delimiter for wordsafe truncation (default: ' ')

License

MIT © Marc Görtz

About

💬 Provides additional truncation functions in PHP.

https://packagist.org/packages/marcgoertz/shorten

License:MIT License


Languages

Language:PHP 100.0%