kzykhys/text
Composer 安装命令:
composer require kzykhys/text
包简介
Simple text manipulation library for PHP5.4
README 文档
README
Do you remember PHP's string functions?
If not, just wrap you text with Text! It will save a minute on your coding.
Text is extracted from kzykhys/Ciconia. this is used for markdown processing.
Installation
Modify your composer.json and run php composer.phar update
{
"require": {
"kzykhys/text":"~1.0.0"
}
}
Requirements
PHP5.4+
Get Started
Text acts like a string
<?php
use KzykHys\Text\Text;
$text = new Text('Lorem Ipsum');
echo $text;
// Lorem Ipsum
Text can also be called statically
<?php
use KzykHys\Text\Text;
$text = Text::create('Lorem Ipsum');
echo $text;
// Lorem Ipsum
Manipulation methods are chainable:
$text = new Text('foo'); $text ->append('bar') // foobar ->prepend('baz') // bazfoobar ->wrap('-') // -bazfoobar- ->upper() // -BAZFOOBAR- ->lower() // -bazfoobar- ->trim('-') // bazfoobar ->rtrim('r') // bazfooba ->ltrim('b') // azfooba ;
Special note for replace()
$text = new Text('FooBarBaz'); $text->replace('/Foo(Bar)(Baz)/', function (Text $whole, Text $bar, Text $baz) { return $bar->upper()->append($baz->lower()); }); echo $text; // BARbaz
If the second argument is callable, callback takes at least one parameter. The whole match being first, and matched subpatterns.
All parameters are Text instance.
API
Manipulation (Chainable)
| Method | Description |
|---|---|
| create($text) | Create a new Text instance. |
| append($text) | Append the string. |
| prepend($text) | Prepend the string. |
| wrap($start, [$end]) | Surround text with given string. |
| lower() | Make a string lowercase. |
| upper() | Make a string uppercase. |
| trim([$charList]) | Strip whitespace (or other characters) from the beginning and end of a string. |
| rtrim([$charList]) | Strip whitespace (or other characters) from the end of a string. |
| ltrim([$charList]) | Strip whitespace (or other characters) from the beginning of a string. |
| escapeHtml([$option]) | Convert special characters to HTML entities. |
| replace($pattern, $replacement) | Perform a regular expression search and replace. If $replacement is the callable, a callback that will be called and passed an array of matched elements in the subject string. |
| replaceString($search, $replace) | Replace all occurrences of the search string with the replacement string. |
| indent([$spaces]) | Add one level of line-leading spaces. |
| outdent([$spaces]) | Remove one level of line-leading tabs or spaces. |
| detab([$spaces]) | Convert tabs to spaces. |
| eachLine($callback) | Apply a user function to every line of the string. |
Test
| Method | Description |
|---|---|
| isEmpty() | Determine whether a variable is empty |
| isNumeric() | Finds whether a variable is a number or a numeric string |
| match($pattern, [&$matches]) | Perform a regular expression match |
Miscellaneous
| Method | Description |
|---|---|
| split($pattern, [$flags]) | Split string by a regular expression |
| lines([$pattern]) | Split string by a line break |
| chars() | Convert a string to an array |
| length() | Gets the length of a string |
| countLines() | Gets the number of lines |
| indexOf($needle, [$offset]) | Find the position of the first occurrence of a substring in a string |
Filesystem
| Method | Description |
|---|---|
| save($path) | Write a string to a file |
License
The MIT License
Author
Kazuyuki Hayashi (@kzykhys)
kzykhys/text 适用场景与选型建议
kzykhys/text 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.62k 次下载、GitHub Stars 达 53, 最近一次更新时间为 2013 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「text」 「box」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kzykhys/text 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kzykhys/text 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kzykhys/text 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Symfony 4/5 Bundle for box spout excel library v3
Ajax Box widget for Yii 2 Framework.
Simple minimal but useful set of utils (properties, strings, datetimes, etc.)
使用简单实用的语义化接口快速读写Excel文件
Common libraries used by Zimbra Api
统计信息
- 总下载量: 4.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 54
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-08-07