code-atlantic/chophper
最新稳定版本:1.0.1
Composer 安装命令:
composer require code-atlantic/chophper
包简介
HTML text truncation library for PHP
README 文档
README
Chophper is a PHP utility for truncating text within HTML to a given length without breaking the HTML tags.
Support for:
- Truncate chars, optionally respecting word boundaries
- Truncate words, optionally respecting sentence boundaries
- Truncate sentences, optionally respecting block boundaries
- Truncate blocks (paragraphs, lists, etc.)
- Preserving HTML tags
- Preserving HTML entities
Note: This is an alpha version. Use at your own risk, and expect API changes towards simple and more flexible usage before the first stable release.
Installation
Install via composer:
composer require code-atlantic/chophper
Usage
// Full is built to fully support HTML5 without breaking the HTML structure. use Chophper\Full as Chophper; $options [ // ... see options below. ]; Chophper::truncate($html, $length, $options);
Options ( current, very subject to change )
| Option | Type | Default | Description |
|---|---|---|---|
ellipsis |
string | … |
The string to append to the truncated text. |
truncateBy |
string | words |
Whether to break the text by chars, words, sentences or blocks |
preserveWords |
boolean | false |
Whether to preserve words when using chars truncation. |
Options (wisthlist)
| Option | Type | Default | Description |
|---|---|---|---|
wordBreak |
boolean | false |
Whether to break the text at word boundaries. |
preserveTags |
boolean | false |
Whether to preserve HTML tags. |
tagsWhitelist |
array | [] |
A list of HTML tags to preserve. |
tagsBlacklist |
array | [] |
A list of HTML tags to remove. |
tagsIngoreLength |
array | [] |
A list of HTML tags to not count towards the length. |
preserveEntities |
boolean | false |
Whether to preserve HTML entities. |
entitiesWhitelist |
array | [] |
A list of HTML entities to preserve. |
entitiesBlacklist |
array | [] |
A list of HTML entities to remove. |
preserveImages |
boolean | false |
Whether to preserve images. |
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-15