https://github.com/mrcgrtz/php-shorten
💬 Provides additional truncation functions in PHP.
https://github.com/mrcgrtz/php-shorten
html markup php shorten truncation wordsafe-truncation
Last synced: about 1 year ago
JSON representation
💬 Provides additional truncation functions in PHP.
- Host: GitHub
- URL: https://github.com/mrcgrtz/php-shorten
- Owner: mrcgrtz
- License: mit
- Created: 2013-01-05T12:06:01.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2025-04-02T04:38:51.000Z (about 1 year ago)
- Last Synced: 2025-04-06T22:32:18.204Z (about 1 year ago)
- Topics: html, markup, php, shorten, truncation, wordsafe-truncation
- Language: PHP
- Homepage: https://packagist.org/packages/marcgoertz/shorten
- Size: 303 KB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Shorten
> Provides additional truncation functions in PHP.
[](https://github.com/mrcgrtz/php-shorten/actions/workflows/test.yml)
[](https://coveralls.io/github/mrcgrtz/php-shorten?branch=main)



[](https://github.com/mrcgrtz/php-shorten/blob/main/LICENSE.md)
## Installation
I recommend using [Composer](https://getcomposer.org/) for installing and using Shorten:
```bash
composer require marcgoertz/shorten
```
Of course you can also just require it in your scripts directly.
## Usage
```php
truncateMarkup('Go to example site', 10);
?>
```
Output:
```html
Go to exam…
```
## Functions
```php
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](https://marcgoertz.de/)