Download the PHP package masakielastic/icu4x without Composer
On this page you can find all versions of the php package masakielastic/icu4x. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download masakielastic/icu4x
More information about masakielastic/icu4x
Files in masakielastic/icu4x
Package icu4x
Short Description ICU4X PHP extension for Unicode text segmentation and East Asian Width, built with ext-php-rs
License MIT
Informations about the package icu4x
ICU4X PHP Extension
A PHP extension for Unicode text segmentation using ICU4X, built with ext-php-rs.
Features
- Grapheme Cluster Segmentation: Proper handling of Unicode text including emojis and complex scripts
- East Asian Width Support: Calculate display width of Unicode characters for proper text layout
- Multiple APIs: Both object-oriented class API and functional API
- SPL Interface Support: Full integration with PHP's Standard PHP Library interfaces
- ICU4X 2.0: Built on the latest ICU4X Unicode library
- Memory Efficient: Rust-based implementation with zero-copy optimizations
Installation
Via PIE (Recommended)
PIE (PHP Installer for Extensions) allows you to install this extension directly from packagist.org.
Then add the extension to your php.ini:
Manual Build
Prerequisites
- Rust 1.70+
- PHP 8.1+
- ext-php-rs 0.14.0
-
Clone the repository:
-
Build and install the extension:
- Add to php.ini:
Usage
Function API (Recommended)
Class API
API Reference
Function API
icu4x_segmenter(string $text, string $mode = 'grapheme', ?string $locale = null): ICU4X\SegmentIterator
Segments the input text into grapheme clusters.
Parameters:
$text(string): The text to segment$mode(string, optional): Segmentation mode, currently only 'grapheme' is supported$locale(string|null, optional): Locale for segmentation rules
Returns: ICU4X\SegmentIterator - An iterator over text segments
icu4x_eaw_width(string $char, ?string $locale = null): int
Calculate the display width of a Unicode character based on its East Asian Width property.
Parameters:
$char(string): The character to calculate width for (only first character is used)$locale(string|null, optional): Locale for ambiguous character handling
Returns: int - Display width (1 or 2), or -1 on error
Examples:
Class API
ICU4X\Segmenter
Main segmenter class for text segmentation.
Constructor:
Methods:
segment(string $text): ICU4X\SegmentIterator- Segment the input textgetMode(): string- Get the current segmentation modegetLocale(): ?string- Get the current locale
ICU4X\SegmentIterator
Iterator class for accessing segmentation results.
Implements: IteratorAggregate, Countable
Methods:
count(): int- Get the number of segmentsgetIterator(): ICU4X\InternalIterator- Get internal iteratortoArray(): array- Convert to array
Examples
Basic Text Segmentation
Unicode and Emoji Support
Working with SPL Interfaces
East Asian Width Examples
Testing
Run the test suite:
For release builds:
Performance
The extension is built on Rust and ICU4X, providing:
- High Performance: Rust's zero-cost abstractions and ICU4X optimizations
- Memory Efficiency: Minimal memory overhead with proper resource management
- Unicode Compliance: Full Unicode 15.0+ support with correct grapheme cluster handling
Supported Unicode Features
- ✅ Grapheme cluster segmentation
- ✅ East Asian Width property calculation
- ✅ Emoji sequences (including ZWJ sequences)
- ✅ Complex scripts (Arabic, Devanagari, etc.)
- ✅ Regional indicator sequences (flag emojis)
- ✅ Modifier sequences
- ✅ Locale-aware ambiguous character handling
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Development Setup
Commit Message Convention
This project follows Conventional Commits:
feat:- New featuresfix:- Bug fixesdocs:- Documentation changeschore:- Maintenance taskstest:- Test additions or modifications
License
[Add your license information here]
Acknowledgments
- ICU4X - Unicode components for Rust
- ext-php-rs - PHP extension framework for Rust
- Unicode Consortium - Unicode standards