hoa/ustring
最新稳定版本:4.17.01.16
Composer 安装命令:
composer require hoa/ustring
包简介
The Hoa\Ustring library.
README 文档
README
Hoa is a modular, extensible and
structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.
Hoa\Ustring
This library allows to manipulate UTF-8 strings easily with some search algorithms.
Installation
With Composer, to include this library into
your dependencies, you need to
require hoa/ustring:
$ composer require hoa/ustring '~4.0'
For more installation procedures, please read the Source page.
Testing
Before running the test suites, the development dependencies must be installed:
$ composer install
Then, to run all the test suites:
$ vendor/bin/hoa test:run
For more information, please read the contributor guide.
Quick usage
We propose a quick overview of two usages: manipulate UTF-8 strings and one search algorithm.
Natural UTF-8 strings manipulation
The Hoa\Ustring\Ustring class allows to manipulate easily UTF-8 strings in a
very natural way. This class implements the \ArrayAccess, \Countable and
\IteratorAggregate interfaces. We will use the following examples:
$french = new Hoa\Ustring\Ustring('Je t\'aime'); $arabic = new Hoa\Ustring\Ustring('أحبك'); $japanese = new Hoa\Ustring\Ustring('私はあなたを愛して');
To get the first character, we will do:
var_dump( $french[0], // string(1) "J" $arabic[0], // string(2) "أ" $japanese[0] // string(3) "私" );
And to get the last character, we will do [-1]. It supports unbounded (and
modulo) indexes.
We note that it cares about text direction. Look at $arabic[0], it returns
أ and not ك. To get the direction, we can use the
Hoa\Ustring\Ustring::getDirection method (which call the
Hoa\Ustring\Ustring::getCharDirection static method), it returns either
Hoa\Ustring\Ustring::LTR (0) or Hoa\Ustring\Ustring::RTL (1):
var_dump( $french->getDirection(), // int(0) $arabic->getDirection(), // int(1) $japanese->getDirection() // int(0) );
Text direction is also important for the append, prepend, pad… methods on
Hoa\Ustring\Ustring for example.
To get the length of a string, we can use the count function:
var_dump( count($french), // int(9) count($arabic), // int(4) count($japanese) // int(9) );
We are also able to iterate over the string:
foreach ($arabic as $letter) { var_dump($letter); } /** * Will output: * string(2) "أ" * string(2) "ح" * string(2) "ب" * string(2) "ك" */
Again, text direction is useful here. For $arabic, the iteration is done from
right to left.
Some static methods are helpful, such as fromCode, toCode or isUtf8 on
Hoa\Ustring\Ustring:
var_dump( Hoa\Ustring\Ustring::fromCode(0x1a9), // string(2) "Ʃ" Hoa\Ustring\Ustring::toCode('Ʃ'), // int(425) == 0x1a9 Hoa\Ustring\Ustring::isUtf8('Ʃ') // bool(true) );
We can also transform any text into ASCII:
$emoji = new Hoa\Ustring\Ustring('I ❤ Unicode'); $maths = new Hoa\Ustring\Ustring('∀ i ∈ ℕ'); echo $emoji->toAscii(), "\n", $maths->toAscii(), "\n"; /** * Will output: * I (heavy black heart) Unicode * (for all) i (element of) N */
Search algorithm
The Hoa\Ustring\Search implements search algorithms on strings.
For example, the Hoa\Ustring\Search::approximated method make a search by
approximated patterns (with k differences based upon the principle diagonal
monotony). If we search the word GATAA in CAGATAAGAGAA with 1 difference, we
will do:
$search = Hoa\Ustring\Search::approximated( $haystack = 'CAGATAAGAGAA', $needle = 'GATAA', $k = 1 ); $solutions = array(); foreach ($search as $pos) { $solutions[] = substr($haystack, $pos['i'], $pos['l']); }
We will found AGATA, GATAA, ATAAG and GAGAA.
The result is not very handy but the algorithm is much optimized and found many applications.
Documentation
The
hack book of Hoa\Ustring contains
detailed information about how to use this library and how it works.
To generate the documentation locally, execute the following commands:
$ composer require --dev hoa/devtools $ vendor/bin/hoa devtools:documentation --open
More documentation can be found on the project's website: hoa-project.net.
Getting help
There are mainly two ways to get help:
- On the
#hoaprojectIRC channel, - On the forum at users.hoa-project.net.
Contribution
Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.
License
Hoa is under the New BSD License (BSD-3-Clause). Please, see
LICENSE for details.
hoa/ustring 适用场景与选型建议
hoa/ustring 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.96M 次下载、GitHub Stars 达 406, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「search」 「string」 「unicode」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hoa/ustring 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hoa/ustring 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hoa/ustring 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
A Laravel package to retrieve data from Google Search Console
Encode integer IDs using a preset or customized symbol set
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
base62 encoder and decoder also for big numbers with Laravel integration
Abstraction Layer to index and search entities
统计信息
- 总下载量: 21.96M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 406
- 点击次数: 14
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-04