mscribellito/str
Composer 安装命令:
composer require mscribellito/str
包简介
Str is an immutable PHP class that provides convenient, object-oriented operations for string handling and manipulation.
README 文档
README
_____ _
/ ____|| |
| (___ | |_ _ __
\___ \ | __|| '__|
____) || |_ | |
|_____/ \__||_|
What is Str?
Str is an immutable PHP class that provides convenient, object-oriented operations for string handling and manipulation. Str provides methods for examining individual characters of the string, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. A Str is immutable (constant) and its value cannot be changed after creation.
Note: Str is not intended to replace all instances of your string variables - just those of which require many string operations and can benefit from an easy to use API.
Requirements
PHP version 7 or newer is required.
Installing
Install via Composer:
composer require mscribellito/str
Require:
require 'path/to/Str.php';
Example Usage
$lipsum = new Str("Lorem ipsum dolor sit amet"); $search = "ipsum"; if ($lipsum->contains($search)) { printf("'%s' contains '%s'", $lipsum, $search); // 'Lorem ipsum dolor sit amet' contains 'ipsum' }
You can also create an instance of Str via a convenient, helper function:
$lipsum = Str("Lorem ipsum dolor sit amet");
Chaining
$str = new Str('php'); echo $str->toUpperCase()->concat(' is a popular general-purpose scripting language'); // PHP is a popular general-purpose scripting language
Constructor Summary
| Constructor and Description |
|---|
Str()Initializes a newly created Str object so that it represents an empty character sequence. |
Str(mixed $original)Initializes a newly created Str object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. |
Str(mixed $original, int $offset, int $count)Initializes a newly created Str object so that it contains characters from a substring of the argument string. |
Method Summary
| Modifier and Type | Method and Description |
|---|---|
string |
__toString()The value of this string is returned. |
string |
charAt(int $index)Returns the character at the specified index. |
int |
charCodeAt(int $index)Returns the character ASCII value at the specified index. |
int |
compareTo(string $str)Compares two strings lexicographically. |
int |
compareToIgnoreCase(string $str)Compares two strings lexicographically, ignoring case differences. |
Str |
concat()Concatenates the specified string(s) to the end of this string. |
bool |
contains(string $str)Returns true if and only if this string contains the specified string. |
bool |
endsWith(string $suffix)Tests if this string ends with the specified suffix. |
bool |
equals(string $str)Compares this string to the specified string. |
bool |
equalsIgnoreCase(string $str)Compares this string to the specified string, ignoring case considerations. |
static Str |
format(string $format)Returns a formatted string using the specified format string and arguments. |
int |
indexOf(string $str, [int $fromIndex=0])Returns the index within this string of the first occurrence of the specified string, optionally starting the search at the specified index. |
bool |
isEmpty()Returns true if and only if length() is 0. |
static Str |
join(string $delimiter, mixed[] $elements)Returns a new string composed of array elements joined together with the specified delimiter. |
int |
lastIndexOf(string $str, [int $fromIndex=0])Returns the index within this string of the last occurrence of the specified character, optionally starting the search at the specified index. |
int |
length()Returns the length of this string. |
bool |
matches(string $regex)Tells whether or not this string matches the given regular expression. |
bool |
regionMatches(int $toffset, string $str, int $ooffset, int $length, [bool $ignoreCase=false])Tests if two string regions are equal. |
Str |
replace(string $target, string $replacement)Returns a string resulting from replacing all occurrences of target in this string with replacement. |
Str |
replaceAll(string $regex, string $replacement)Replaces each substring of this string that matches the given regular expression with the given replacement. |
Str |
replaceFirst(string $regex, string $replacement)Replaces the first substring of this string that matches the given regular expression with the given replacement. |
Str[] |
split(string $regex, [int $limit=null])Splits this string around matches of the given regular expression. |
bool |
startsWith(string $prefix, [int $toffset=0])Tests if this string starts with the specified prefix, optionally starting the search at the specified index. |
Str |
substring(int $beginIndex, [int $endIndex=null])Returns a string that is a substring of this string. |
string[] |
toCharArray()Converts this string to a new character array. |
Str |
toLowerCase()Converts all of the characters in this string to lower case. |
Str |
toUpperCase()Converts all of the characters in this string to upper case. |
Str |
trim([string $characterMask=" \t\n\r\0\x0B"])Returns a string whose value is this string, with any leading and trailing whitespace removed. |
Testing
Run tests with vendor/bin/phpunit
License
Released under the MIT License. See LICENSE for details.
mscribellito/str 适用场景与选型建议
mscribellito/str 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「string」 「str」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mscribellito/str 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mscribellito/str 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mscribellito/str 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Encode integer IDs using a preset or customized symbol set
base62 encoder and decoder also for big numbers with Laravel integration
PHP string processing library.
Сумма прописью
Utility classes meant to facilitate object manipulation.
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-20