André's Blog

PHP, Zend Framework, Mac/Cocoa Programming

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.

About these ads

Written by andrehoffmann

October 15, 2006 at 3:22 pm

2 Responses

Subscribe to comments with RSS.

  1. First one to comment? Aww! So let me say thanks for Zend_Locale_UTF8! :)

    Can you tell me, are API docs somewhere available? Also, in general for packages of the ZendFramework? I just managed to find the docs for Core.

    till

    March 2, 2007 at 4:42 pm

  2. The team of the Zend Framework decided to go with PHP’s ctype extension and therefore raise the requirements for the ZF.

    Using ctype, there was no longer a need for an UTF-8 library(at least not for the usage of this particular framework).

    If you’re still interested in using this library here’s what you got to do.

    First of all download the source of the ZF 0.2.0 (which can be obtained via svn. see: http://framework.zend.com/svn/framework/tag/release-0.2.0/).

    Secondly here’s some code for testing purposes which should help you getting started:

    <?php
    set_include_path( get_include_path() . PATH_SEPARATOR . '/srv/www/htdocs/ZF/library' . PATH_SEPARATOR . '/srv/www/htdocs/ZF/incubator/library' );
    error_reporting( E_ALL | E_STRICT );

    require_once 'Zend.php';
    require_once 'Zend/Locale/UTF8.php';
    class index {

         public static function run() {
        
             /*
             * 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';

             //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('schön');

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

             echo $string1->lastIndexOf( $string2 );
             echo $string1->__toString().'<br />';

             //replace "ön" with "ade" schön(beautiful) -> schade(too bad)
             echo $string1->replace('ön', 'ade')->__toString().'<br />';

             echo $string1->concat(', schön')->__toString().'<br />';

             echo $string1->substring(2, 6);

             //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); //ö

             //compare a string to another one
             echo $string2->equals('señorita');
         }
    }

    <html>
        <head>
             <meta http-equiv="content-type" content="text/html; charset=utf-8" />
         </head>
         <body>
             <p>
    <?php
    try {
         index::run();
    } catch ( Zend_Locale_UTF8_Exception $e ) {
         var_dump($e);
    }

    ?>
             </p>
         </body>
    </html>

    andrehoffmann

    March 2, 2007 at 8:08 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: