2017 © Pedro Peláez
 

library trimmer

Helps trimming string to given length rounded to whole words.

image

pawelzny/trimmer

Helps trimming string to given length rounded to whole words.

  • Sunday, December 11, 2016
  • by pawelzny
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 29 % Grown

The README.md

Trimmer

Trimmer provide support for string trimming to given length methods, and also trimming with words aware. Will not cut word in half., (*1)

Installation:

If composer is installed globally in your OS:, (*2)

composer require pawelzny/trimmer

If composer is installed locally in your project directory:, (*3)

php composer.phar require pawelzny/trimmer

Get started

Use facade to access Trimmer objects or import proper class and use directly., (*4)

Trim to characters length:

<?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...

Trim to words length:

<?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...

API

Builds in constants:

<?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; // ...

Facade:

Trim::chars()

CharsTrimmer: constructor(string: $string [, int: $length=null [, string: $delimiter=null]]), (*5)

Trim::words()

WordsTrimmer: constructor(string: $string [, int: $length=null [, string: $delimiter=null]]), (*6)

<?PHP

use Trimmer\Trim;

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

Methods:

Trim

string: trim(), (*7)

Performs trimming on string and return new trimmed string, (*8)

<?PHP

use Trimmer\Trim;

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

Set new length

null: setLength(int: $length), (*9)

Caution!: delimiter length will be automatically substracted from trimming length., (*10)

<?PHP
use Trimmer\Trim;

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

Set Delimiter

null: setDelimiter(string: $delimiter), (*11)

<?PHP
use Trimmer\Trim;

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

Without Facade

If you do not want to use facade you can create objects directly., (*12)

<?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();

The Versions

11/12 2016

dev-master

9999999-dev

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words

11/12 2016

v2.0.3

2.0.3.0

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words

10/12 2016

v2.0.2

2.0.2.0

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words

10/12 2016

v2.0.1

2.0.1.0

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words

10/12 2016

dev-words_tokenizer

dev-words_tokenizer

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words

05/12 2016

v2.0.0

2.0.0.0

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words

01/11 2016

1.0.1

1.0.1.0

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words

30/10 2016

1.0.0

1.0.0.0

Helps trimming string to given length rounded to whole words.

  Sources   Download

ISC

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

string trim length words