CentralNic Unicode Library (Unicode.php)
The CentralNic Unicode Library provides some PHP classes for maniuplating Unicode data. These classes are general purpose but are intended for use when working with Internationalised Domain Names (IDNs).
Existing support for Unicode and multi-byte strings in PHP is not great, requiring either an extension that is not compiled into PHP by default, or one of a number of third-party libraries, most of which are not currently maintained (for example, the I18N_UnicodeString class in PEAR was last updated in August 2004).
There is a Unicode extension under development, but it isn't public yet, and again requires a third party library to do the heavy lifting, so probably won't be enabled in a default PHP build.
Proper Unicode support is planned for PHP 6, but given the very slow upgrade rate among web hosting providers (most sites still only support PHP 4), widespread availability remains a long way in the future.
Using the CentralNic Unicode Library is as simple as downloading the current release, and including the main Unicode.php file from your scripts. You then get instant access to the two Unicode_String and Unicode_Character classes.
Download
The current release is php-Unicode-0.1.2.tar.gz (August 26, 2008).
Documentation
Click here for full documentation for this library. This documentation is included in the standard release.
Example Usage
<?php
require('Unicode.php');
$string = new Unicode_String();
$string->fromUTF8("Ĥēĺļŏ, Ŵőřļď!");
print "String contains ".$string->length()." characters.\n";
print "String contains characters from the following blocks:".implode(', ', $string->blocks())."\n";
print "String in UTF-8: ".$string->toUTF8()."\n";
print "String in UPPERCASE: ".$string->toUpper()->toUTF8()."\n";
$comma = new Unicode_Character(ord(','));
$words = explode($comma);
foreach ($words as $word) {
print "Word has ".$word->length()." characters.\n";
}
?>
License
The CentralNic Unicode Library is released under the GNU Library General Public License, version 2.0. This is not the "Lesser" GPL (version 2.1 and higher), which is more restrictive.
The use of the Library GPL means that you can use the code in your own proprietary software. While you are not obliged to pass back any changes you make to the code, we would greatly appreciate it if you did.
Contact
This library is "alpha" sofware and certainly contains errors. If you discover one, and want to let us know, please e-mail .
Click here for engineering and software development jobs at CentralNic