承接 pawelzny/trimmer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pawelzny/trimmer

Composer 安装命令:

composer require pawelzny/trimmer

包简介

Helps trimming string to given length rounded to whole words.

README 文档

README

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

Installation:

If composer is installed globally in your OS:

composer require pawelzny/trimmer

If composer is installed locally in your project directory:

php composer.phar require pawelzny/trimmer

Get started

Use facade to access Trimmer objects or import proper class and use directly.

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]])

Trim::words()

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

<?PHP

use Trimmer\Trim;

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

Methods:

Trim

string: trim()

Performs trimming on string and return new trimmed string

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

Caution!: delimiter length will be automatically substracted from trimming length.

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

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

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

统计信息

  • 总下载量: 37
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: ISC
  • 更新时间: 2016-10-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固