This is kinda port of python's jquast/wcwidth
$ composer require alecrabbit/php-wcwidthuse 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 consideredsee doc/usage.md for more details.
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=trueNote When using
ffiextensionversionvalue is ignored completely.


