Provides additional truncation functions in PHP.
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.
<?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>…
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:' '
)
MIT © Marc Görtz