PHP code example of sashabo / shortener

1. Go to this page and download the library: Download sashabo/shortener library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sashabo / shortener example snippets


Shortener::shortenText(string $source, int $length = 50, string $add = '...', bool $multiSpace = false): string

$shortener = new TextShortener('Lorem ipsum dolor');
echo $shortener->shorten(10, '...');
 
Shortener::shortenHtml(string $source, int $length = 50, string $add = '...'): string
 
$shortener = new HtmlShortener('<u>Lorem <i>ipsum</i> dolor sit amet</u>');
echo $shortener->shorten(26, '...');
echo $shortener->shorten(25, '...');
echo $shortener->shorten(10, '...');
echo $shortener->shorten(6, '...');
shorten_text
twig
{{ 'Lorem ipsum dolor sit amet' | shorten_text(25, '...') }}

{{ '<u>Lorem <i>ipsum</i> dolor sit amet</u>' | shorten_html(25, '...') }}