marcgoertz / shorten
Provides truncation functions.
Installs: 8 781
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 1
Forks: 2
Open Issues: 2
Requires
- php: >=8.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.4.3
- phpunit/phpunit: ^9.5.4
- squizlabs/php_codesniffer: ^3.6.0
This package is auto-updated.
Last update: 2024-11-02 10:13:37 UTC
README
Provides additional truncation functions in PHP.
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