cybercog / php-unicode
PHP Unicode 库
1.0.0
2024-01-04 12:58 UTC
Requires
- php: ^8.1
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2024-09-08 11:16:47 UTC
README
简介
简化 Unicode 字符串和字符(码点)操作。面向对象实现。
安装
通过 Composer 引入包。
composer require cybercog/php-unicode
使用
实例化 Unicode 字符串
$string = \Cog\Unicode\UnicodeString::of('Hello');
UnicodeString
对象将包含一系列 Unicode 字符。
例如,Unicode 字符串 "Hello" 由以下码点表示
- U+0048 (H)
- U+0065 (e)
- U+006C (l)
- U+006C (l)
- U+006F (o)
表示 Unicode 字符串
$string = \Cog\Unicode\UnicodeString::of('Hello'); echo strval($string); // (string) "Hello"
实例化 Unicode 字符
$character = \Cog\Unicode\Character::of('ÿ'); $character = \Cog\Unicode\Character::ofDecimal(255); $character = \Cog\Unicode\Character::ofHexadecimal('U+00FF'); $character = \Cog\Unicode\Character::ofHtmlEntity('ÿ'); $character = \Cog\Unicode\Character::ofXmlEntity('ÿ');
以任何格式表示 Unicode 字符
$character = \Cog\Unicode\Character::of('ÿ'); echo strval($character); // (string) "ÿ" echo $character->toDecimal(); // (int) 255 echo $character->toHexadecimal(); // (string) "U+00FF" echo $character->toHtmlEntity(); // (string) "ÿ" echo $character->toXmlEntity(); // (string) "ÿ"
许可证
PHP Unicode
包是开源软件,由 MIT 许可证许可,由 Anton Komarev 提供。
关于 CyberCog
CyberCog 是一个爱好者的社交联盟。研究产品与软件开发中的最佳解决方案是我们的热情。