alecrabbit/php-wcwidth

Calculate width of unicode strings rendered to a terminal

Maintainers

👁 alecrabbit

Package info

github.com/alecrabbit/php-wcwidth

pkg:composer/alecrabbit/php-wcwidth

Statistics

Installs: 37 666

Dependents: 2

Suggesters: 0

Stars: 4

Open Issues: 4

1.0.0 2023-09-21 10:58 UTC

Requires

  • php: >=8.2

Suggests

  • ext-ffi: For FFI bindings.
  • ext-mbstring: For multibyte Unicode string functionality.

Provides

None

Conflicts

None

Replaces

None

MIT 5c682ac4c86362816b152b6affaf4313a851a61d

phpcliconsolewcwidthwcswidth


README

👁 PHP Version
👁 Build Status

👁 Build Status
👁 Scrutinizer Code Quality
👁 Code Coverage

👁 Latest Stable Version
👁 Latest Stable Version
👁 Latest Unstable Version

👁 License
👁 Total Downloads

This is kinda port of python's jquast/wcwidth

🌐 Unicode release files

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 extension version value is ignored completely.