A well-structured and easy-to-use PHP class providing access to Unicode utilities. This class allows working with Unicode characters in a type-safe and explicit manner for PHP applications by providing constants and methods to retrieve subsets of characters, escape Unicode sequences, and more.
- Unicode constants for type-safe and explicit declarations
- Retrieve all Unicode constants defined in the class
- Fetch a subset of Unicode constants by count or range
- Convert UTF-8 characters to Unicode escape sequences
- Provides structured access to Unicode symbols
- Ensures strict type safety for better maintainability
use Rayblair\Unicode\Unicode;
echo Unicode::HYPHEN_MINUS; // Outputs: -
$mappings = [
Unicode::EN_DASH => Unicode::HYPHEN_MINUS,
Unicode::EM_DASH => Unicode::HYPHEN_MINUS,
];- Install via Composer:
composer require rayblair/unicodeuse Rayblair\Unicode\Unicode;
// Get single Unicode constant
print_r(Unicode::HYPHEN_MINUS); // Outputs: -
// Get all Unicode constants
print_r(Unicode::getAll());
// Get first 10 Unicode constants
print_r(Unicode::get(10));
// Get Unicode characters within a specific range
print_r(Unicode::range('0041', '0044'));
// Convert UTF-8 characters into Unicode escape sequences
echo Unicode::escape('A'); // Outputs \u0041Returns an associative array of all defined Unicode constants.
print_r(Unicode::getAll());Output Example:
Array
(
[LATIN_CAPITAL_LETTER_A] => A
[LATIN_CAPITAL_LETTER_B] => B
[LATIN_SMALL_LETTER_A] => a
)Returns a subset of Unicode constants up to the given count.
print_r(Unicode::get(5));Returns a subset of Unicode constants within a specified Unicode hex range.
print_r(Unicode::range('0041', '0044'));Output:
Array
(
[LATIN_CAPITAL_LETTER_A] => A
[LATIN_CAPITAL_LETTER_B] => B
[LATIN_CAPITAL_LETTER_C] => C
[LATIN_CAPITAL_LETTER_D] => D
)Converts UTF-8 characters into Unicode escape sequences (\uXXXX).
echo Unicode::escape('Hello, 😊!'); // Outputs: \u0048\u0065\u006c\u006c\u006f, \u1F60A!- PHP 8.0 and above
Contributions are welcome! If you have improvements or additional Unicode symbols to add, feel free to:
- Fork the repository
- Create a new branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License. See the LICENSE file for more details.
For issues or suggestions, feel free to open an issue on GitHub.
If you find this project useful, consider giving it a ⭐ on GitHub!