André's Blog

PHP, Zend Framework, Mac/Cocoa Programming

Archive for the ‘Zend_UTF8’ Category

Zend_Locale_UTF8: Functionality Update

with 2 comments

I finally found the time to add new functions to Zend_Locale_UTF8:

Still missing are: Unit-Tests, ctype functions, mbstring and PHP6 support.

So long.

Written by andrehoffmann

October 15, 2006 at 3:22 pm

Initial Release of Zend_Locale_UTF8

leave a comment »

I just released the first version of Zend_Locale_UTF8.It doesn’t come with all functions nor with the best performance, but it shows how the current state of development is.Missing features:

  • Unit-Tests
  • substr()
  • strrpos() (not such a big of a deal as it’s basically the same as strpos, I just wanted to make a cut at some point)
  • strtr()
  • strtok()
  • PHP6 support
  • mbstring support

Now that the basic functionalities are implemented it will be easy to code the other stuff.

Next draft: Unit-Tests

PS: Thanks to Willie and Andries Seuters who helped me to find a bug yesterday that’s been pausing the development for quite a long time.

Now I’ll give a little insight on how to use Zend_Locale_UTF8:
/*
* the api basically looks like the one of a java string object,
* so if you know java these examples should look very familiar
*
* @see http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
*/

require_once ‘Zend/Locale/UTF8.php’;

//let’s create a string..
$string1 = Zend_Locale_UTF8::string(‘schön, señorita, ﻹډ, €’);

//let’s output it
echo $string1;

// and convert it to upper case
echo $string1->toUpperCase();

//to lower
echo $string1->toLowerCase();

//create another string
$string2 = Zend_Locale_UTF8::string(‘señorita’);

//and look where it can be found in string1
echo $string1->indexOf($string2);

//this works as well:
echo $string1->indexOf(‘,’);

//now lets check whether or not $string2 can be found in $string1
echo $string1->contains($string2);

//again, this works too
echo $string1->contains(‘señorita’);

//output the length of string1
echo $string1->length();

//let’s output the character at position 3
echo $string1->charAt(3); //ö

Written by andrehoffmann

October 3, 2006 at 3:56 pm

Zend_UTF8 – New API Design

leave a comment »

A while ago, I designed the API of Zend_UTF8 to be similar to PHP5’s string functions. So f.e. you just would have had to call Zend_UTF8::strlen() to get the length of a string. I actually wanted to do it that way for PHP6 compatibility reasons.

I gave up on that, as its performance is just too bad. Instead of that, there’s going to be a string object (basically the same API as the Java String Object, so Java developers should be familiar with it) which allows to perform way better, since a string becomes a constant and it won’t have to do the UTF-8 transformation over and over again. There is also going to be a string object for PHP6 which basically does the same while using the PHP6’s string functions.

That might result in more work once we raise the Zend Framework’s requirements to PHP6, but till then it will perform better, which in my opinion is way more important.

Written by andrehoffmann

September 27, 2006 at 11:42 pm