alecrabbit / php-wcwidth
Calculate width of unicode strings rendered to a terminal
Installs: 9 672
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 4
Requires
- php: >=8.2
Requires (Dev)
- nunomaduro/collision: ^7.0
- phpunit/phpunit: ^10.0
- symfony/cache: ^6.2
- symfony/console: ^6.2
- symfony/http-client: ^6.2
- symfony/var-dumper: ^6.2
- twig/twig: ^3.5
Suggests
- ext-ffi: For FFI bindings.
- ext-mbstring: For multibyte Unicode string functionality.
This package is auto-updated.
Last update: 2024-12-10 11:33:17 UTC
README
This is kinda port of python's jquast/wcwidth
Installation
$ composer require alecrabbit/php-wcwidth
Quick start
use function AlecRabbit\WcWidth\wcwidth; use function AlecRabbit\WcWidth\wcswidth; echo wcwidth('a'); // 1 echo wcwidth('é'); // 1 echo wcwidth('🐘'); // 2 echo wcswidth('🐘🐘🐘'); // 6 echo wcwidth('🐘🐘🐘'); // 2 - only first char is considered
see doc/usage.md for more details.
FFI extension
Note ‼️ Experimental feature.
For improved performance, consider leveraging the Foreign Function Interface (FFI
) extension, if available. To enable
this feature, set the USE_FFI
environment variable to true
.
USE_FFI=true
Note When using
ffi
extensionversion
value is ignored completely.