Spiga

php class for Unicode Manipulation

January 03, 09 by Gabi Solomon

If you ever had to build a site in a language that had special characters or a multilanguage website, then you have had problems with UTF encoding for sure.

Well recently a new class was published on phpclasses.org by Rubens Takiguti Ribeiro called Unicode Manipulation that will solve your problems.
The class is a complete solution to manipulate Unicode encoded text with support for UTF-16 and UTF-32 besides UTF-8.

This class can be used to manipulate text with Unicode encodings.

It can perform several types of operations that involve text strings encoded as UTF-8, UTF-16 or UTF-32, like:

- Get the text sequence for byte order mark for little and big endian
- Convert a given character code to Unicode encoded text and vice-versa
- Get the byte length of a given Unicode encoded character
- Convert text encoding between UTF-8, UTF-16 and UTF-32
- Get a part of an Unicode encoded string from a given position and an optional length
- Get the string length of an Unicode encoded text
- Determine whether a given string has Unicode encoded text

[Class Page]

Hope you find it usefull,
Cheers.

[php class] Open Inviter – Get contacts of friends of different networks

December 01, 08 by Gabi Solomon

Yet another great class found on the php classes website.
This one has been in my draft folder for a while (the place i keep my articles ideas ), and finally it came time to write about it (manage to put my laziness away and write it).

The class is called open Inviter and has received the rank of november 2008 Nominee for Innovation Award. I personally hope it will win it, i think it really deserves it.

Describtion

This package can be use to get the contacts of friends of different e-mail providers and social networks.

It can access the Web services servers of different networks to retrieve the contacts of friends of a given user.

Each network is accessed by the means of plug-in classes. Some plug-ins support sending invitation messages to friends to be added to the user contacts.

The class currently comes with plug-ins that support :
* AOL
* GMail
* GMX.net
* Windows Live (Hotmail)
* Katamail
* Lycos
* Mail.com
* Mail.ru
* Rambler.ru
* Rediff
* Yahoo!
* Yandex
* Facebook
* Hi5
* LinkedIn
* MySpace
* Orkut
* Twitter

The class is very easy to use, and comes with a very detailed example of how you can implement it.

[Class full description & download link]

Hope it helps you in your development.

Cheers.

[phpclass] dinamicParams – Calling function with named params

November 23, 08 by Gabi Solomon

A lot of time while developing a function or a method of a class you need to specify 1, 2 or 3 parameters as inputs for that function or method. But usually as you develop further you might end-up in the situation where you would want to add a new parameter to your function.

And so you might have coded a function that has 5 or more parameters, and although it works fine, eventually you will want to call that function and leave the first 4 parameters with the default value and only change the last one. I ended up here a lot of times, and normally in php there is nothing you can do.

A workaround would be to specify the params as a single array variable, but that is just making you write more code and it looks really bad ( at least in my opinion).

Well today i found a new method of doing this in php5 with the help of the Reflection API that is offer in php5. I will not get into to much details about what it does, you can read that in the documentation, basicly it provides a way to reverse-engineer classes, interfaces, functions and methods.

So i wrote a simple class that is going to solve that problem.

With the help of the Reflection API from php5 the class will allow you to call function and methods by providing the parameters as an array specifying names and values even if the original function or methods receives them in the normal fashion.

But enough talk, heres the example.

PHP:
  1. <?php
  2. require('dinamicParams.class.php');
  3.  
  4. class news {
  5.  
  6.     function fetch ( $id, $page = 0, $items_pp = 10, $order_by = 'date', $method = 'desc') {
  7.         echo "
  8.             id: $id,
  9.             page: $page,
  10.             items_pp: $items_pp,
  11.             order_by: $order_by,
  12.             method: $method
  13.         ";
  14.     }
  15.  
  16. }
  17.  
  18.  
  19.  
  20. $news = new news();
  21. $dinamicParams = new dinamicParams();
  22.  
  23. $dinamicParams->call(array($news, 'fetch'), array('order_by' => 'name'));

This will output :

id: , page: 0, items_pp: 10, order_by: name, method: desc

This class is based on this implementation of the reflection API.
It is available on phpclasses can be downloaded here