fab2s/strings
Composer 安装命令:
composer require fab2s/strings
包简介
A purely static String Helper to handle more advanced utf8 string manipulations
关键字:
README 文档
README
A purely static String Helper to handle more advanced utf8 string manipulations
Installation
Strings can be installed using composer:
composer require "fab2s/strings"
Strings is also included in OpinHelper which packages several bellow "Swiss Army Knife" level Helpers covering some of the most annoying aspects of php programing, such as UTF8 string manipulation, high precision Mathematics or properly locking a file
Should you need to work with php bellow 7.1, you can still use OpinHelper 0.x
Prerequisites
As it requires Utf8, Strings requires mb_string, ext-intl is auto detected and used when available for UTF-8 Normalization
In practice
Strings implement some basic text manipulation function that can be pretty useful IRL
-
filter(string $string):stringDrops Zero Width white chars, normalizes EOL and Normalize UTF8 if ext-intl is available
-
singleWsIze(string $string, bool $normalize = false, bool $includeTabs = true):stringReplace repeated white-spaces to a single one, preserve original white-spaces unless normalized (every white-spaces to ' '), with or without tabs (\t)
-
singleLineIze(string $string):stringMake string fit in one line by replacing EOLs and white-spaces to normalized single white-spaces
-
dropZwWs(string $string):stringRemove Zero Width white-spaces
-
normalizeWs(string $string, bool $includeTabs = true, int $maxConsecutive = null):stringNormalize white-spaces to a single
by default, include tabs by default -
normalizeEol($string, $maxConsecutive = null, $eol = self::EOL):stringNormalize EOLs to a single LF by default
-
normalizeText(string $text):stringReturn
trim'd andfilter'd $text -
normalizeTitle(string $title):stringReturn
singleLineIze'd,normalizeWs'd,normalizeText'd anducfirst'd $title (" the best ever \t\r\n article"->"The best ever article") -
normalizeName(string $name):stringReturn
ucword'd andnormalizeTitle'd $name ("john \n\t doe "->"John Doe") -
escape(string $string, int $flag = ENT_COMPAT, bool $hardEscape = true):stringhtmlspecialchars() wrapper with UTF8 set as encoding
-
softEscape(string $string, int $flag = ENT_COMPAT):stringShortcut for
escape(string $string, $flag, true) -
unEscape(string $string, int $quoteStyle = ENT_COMPAT):stringhtmlspecialchars_decode() wrapper
-
convert(string $string, string $from = null, string $to = self::ENCODING):stringConvert encoding to UTF8 by default. Basic $from encoding detection using
Strings::detectEncoding() -
detectEncoding(string $string):string|nullDetect encoding by checking
Utf8::isUf8(), then trying with BOMs and ultimately fall back to mb_detect_encoding() with limited charsets first, then more internally in mb_convert_encoding() -
secureCompare(string $test, string $reference):boolPerform a Timing Attack safe string comparison (Truly constant operations comparison)
-
contentHash(string $content):stringReturn a
sha256hash of the $content prefixed with $content length. Indented to quickly and reliably detect $content updates.
Requirements
Strings is tested against php 7.2, 7.3, 7.4 and 8.0
Contributing
Contributions are welcome, do not hesitate to open issues and submit pull requests.
License
Strings is open-sourced software licensed under the MIT license
fab2s/strings 适用场景与选型建议
fab2s/strings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 321.72k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「Simple」 「utf8」 「utf-8」 「helper」 「strings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fab2s/strings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fab2s/strings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fab2s/strings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple library for make Lexer and Parsers to build a language
A simple library that allows transform any kind of data to native php data or whatever
A simple library that uses the hydration pattern to fill objects given different sources of data.
utf8 util
Removes invalid UTF-8 characters from the given text
Country Flag Emoji for PHP
统计信息
- 总下载量: 321.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 31
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-15