Skip to content

mrcgrtz/php-shorten

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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