- What is cybercog/php-unicode used for?
- It is a lightweight PHP library that provides Unicode-aware string helpers so multibyte text behaves predictably. It covers common operations such as character length, substrings, case conversion, and character inspection. You reach for it when native byte-based string functions would miscount or split non-ASCII text.
- How do I install cybercog/php-unicode with Composer?
- Install it with Composer by running composer require cybercog/php-unicode in your project root. Composer resolves the package and registers its autoloading so the helpers are available in your code. Check the repository's composer.json for the exact PHP constraint before adding it to an older application.
- Does cybercog/php-unicode work with Laravel?
- Yes. It is a plain Composer package, so it installs into a Laravel application like any other dependency and can be used in controllers, jobs, models, and Blade views. No Laravel-specific setup is required beyond Composer autoloading. If you want dependency injection or a facade, you can wrap the library yourself in a small service provider.
- How is cybercog/php-unicode different from Laravel's Str helper?
- Laravel's Str class already wraps many mbstring functions, so there is overlap for length, casing, and substrings. This package is framework-agnostic and focuses only on Unicode string handling, which makes it usable in non-Laravel code and small shared packages. Choose it when you want those helpers without pulling in the full framework.
- Does cybercog/php-unicode require the mbstring extension?
- Unicode-aware length, substring, and case operations typically depend on PHP's mbstring extension or an equivalent polyfill. Make sure mbstring is enabled in your environment, since it is common but can be missing from minimal container images. Verify the extension in your deployment image before relying on multibyte behavior.
- Which PHP and Laravel versions does cybercog/php-unicode support?
- The authoritative answer is in the package's composer.json and its release tags on GitHub. Because it is a standalone PHP library, its PHP constraint matters more than any Laravel version. Check those constraints before upgrading PHP or Laravel in production.
- How do I get the correct length of an emoji or accented string?
- Use the library's length helper instead of strlen, which counts bytes and overcounts multibyte characters. The Unicode-aware helper counts characters so emoji and accented letters are treated as single units. That makes validation rules such as max length behave the way users expect.
- How do I safely truncate or take a substring of multibyte text?
- Native substr can cut a multibyte character in half and produce invalid output. The package's substring helper operates on characters rather than bytes, so accented letters and emoji stay intact. This is useful for previews, truncation, and excerpt generation in Laravel views.
- Can I inspect individual characters in a Unicode string?
- Yes, character inspection helpers are part of the library's Unicode-aware feature set, letting you examine a string character by character instead of byte by byte. This helps with tasks such as counting distinct characters, validating input, or debugging unexpected output. It is simpler than manually walking mb_substr offsets.
- Is cybercog/php-unicode maintained and safe for production?
- It is a small, dependency-light library limited to string operations, so the risk surface is low. Pin a specific version in composer.json and cover your multibyte use cases with tests using accented text, CJK characters, and emoji. Since it is third-party code, review recent release activity on the repository before depending on it long term.