cybercog/php-unicode

PHP Unicode library

1.0.0 2024-01-04 12:58 UTC

This package is auto-updated.

Last update: 2024-12-08 11:54:48 UTC


README

Releases Build License

Introduction

Streamline Unicode strings and characters (code points) manipulations. Object oriented implementation.

Installation

Pull in the package through Composer.

composer require cybercog/php-unicode

Usage

Instantiate Unicode String

$string = \Cog\Unicode\UnicodeString::of('Hello');

UnicodeString object will contain a list of Unicode characters.

For example, the Unicode string "Hello" is represented by the code points:

  • U+0048 (H)
  • U+0065 (e)
  • U+006C (l)
  • U+006C (l)
  • U+006F (o)

Represent Unicode String

$string = \Cog\Unicode\UnicodeString::of('Hello');

echo strval($string); // (string) "Hello"

Instantiate Unicode Character

$character = \Cog\Unicode\Character::of('ÿ');

$character = \Cog\Unicode\Character::ofDecimal(255);

$character = \Cog\Unicode\Character::ofHexadecimal('U+00FF');

$character = \Cog\Unicode\Character::ofHtmlEntity('ÿ');

$character = \Cog\Unicode\Character::ofXmlEntity('ÿ');

Represent Unicode Character in any format

$character = \Cog\Unicode\Character::of('ÿ');

echo strval($character); // (string) "ÿ"

echo $character->toDecimal(); // (int) 255

echo $character->toHexadecimal(); // (string) "U+00FF"

echo $character->toHtmlEntity(); // (string) "ÿ"

echo $character->toXmlEntity(); // (string) "ÿ"

License

About CyberCog

CyberCog is a Social Unity of enthusiasts. Research the best solutions in product & software development is our passion.

CyberCog