PHP code example of pawelzny / trimmer

1. Go to this page and download the library: Download pawelzny/trimmer 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/ */

    

pawelzny / trimmer example snippets


<?PHP
use Trimmer\Trim;

$string = "Far far away, behind the word mountains,
          far from the countries Vokalia and Consonantia, there live
          the blind texts. Separated they live in Bookmarksgrove right
          at the coast of the Semantics, a large language ocean.";


$trim = Trim::chars($string, $length=40);

echo $trim->trim(); // Far far away, behind the word mountai...

<?PHP
use Trimmer\Trim;

$string = "Far far away, behind the word mountains,
          far from the countries Vokalia and Consonantia, there live
          the blind texts. Separated they live in Bookmarksgrove right
          at the coast of the Semantics, a large language ocean.";

$trim = Trim::words($string, $length=40);

echo $trim->trim(); // Far far away, behind the word...

<?PHP
use Trimmer\Trim;

echo Trim::ELLIPSIS; // ...
echo Trim::EOL; // [end of line]
echo Trim::SPACE; // [white space]
echo Trim::TABULATOR; // [tab character]
echo Trim::DEFAULT_DELIMITER; // ...

<?PHP

use Trimmer\Trim;

$chars = Trim::chars($string, $length=30, $delimiter='');
$words = Trim::words($string, $length=30, $delimiter='');

<?PHP

use Trimmer\Trim;

$string = 'Far far away, behind the word mountains';
Trim::chars($string)->trim();
Trim::words($string)->trim();

<?PHP
use Trimmer\Trim;

$string = 'Far far away, behind the word mountains';
$trim = Trim::chars($string);
$trim->setLength(30);

<?PHP
use Trimmer\Trim;

$string = 'Far far away, behind the word mountains';
$trim = Trim::chars($string);
$trim->setDelimiter('[read more]');

<?PHP

use Trimmer\Services\WordsTrimmer;
use Trimmer\Services\CharsTrimmer;
use Trimmer\Trim;

$string = 'Far far away, behind the word mountains';
$length = 30;
$delimiter = Trim::DEFAULT_DELIMITER;

$chars = new CharsTrimmer($string, $length, $delimiter);

$newDelimiter = 'read more...';
$newLength = 40;

$chars->setDelimiter($newDelimiter);
$chars->setLength($newLength);
$chars->trim();

$words = new WordsTrimmer($string, $length, $delimiter);
$words->setDelimiter($newDelimiter);
$words->setLength($newLength);
$words->trim();

php composer.phar