Archive for the 'Uncategorized' Category

Use UTF-8 in Zend Framework 1 without the use of utf8_encode() and utf8_decode()

A problem that I was often had trouble with it, is when I use special characters such as French characters like save it in the database and display it again correctly.
There are some important steps to follow so you can show the text without encoding methods such utf8_encode(), iconv(), mb_convert_encoding(), …

Now go start to work in Zend Framework 1:
You get a database “utf8_general_ci” collation.

In your config. Ini file add the following database settings:
; database information
resources.db.adapter = PDO_MYSQL = localhost
resources.db.params.username = root
resources.db.params.password = root
resources.db.params.dbname = mydatabase
resources.db.isDefaultTableAdapter = true
resources.db.params.driver_options.1002 = “SET NAMES UTF8;”

The last line is very important, it ensures that your data is retrieved in UTF-8.

More info:
SET NAMES indicates what character set the client will use to send SQL statements to the server. Thus, SET NAMES ‘cp1251′ tells the server, “future incoming messages from this client are in character set cp1251.” It also specifies the character set that the server should use for sending results back to the client. (For example, it indicates what character set to use for column values if you use a SELECT statement.)

In your header add next following meta tag:
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

Another little tip, when using Zend_Mail() remember:

$mail = new Zend_Mail(‘UTF-8′);

And now we can work without any problem using UTF-8 characters as in the French language.

Post to Twitter

Php Zend framework connection with Twitter (Oauth)

After a lot of puzzling with a connection to twitter to put a post on my wall, I thought of writing it down so that I never have to puzzle with this again!

After making a Twitter account and an application on

You need 2 actions in you Controller. The first one that you call asks for allowing the connection:

The second action is the callback, that reads the token that you get when you allow the twitter access. This token we will save in a database for further usage.

In my example I have an IndexController with 2 actions named: indexAction() and callbackAction().
The url of the page is “” and my callback url is “”.
You need to specify this in your twitter app settings. You go to your app that you can find on and change the settings with your url and your callback url.

Now we can start in our Zend Framework.
Continue reading ‘Php Zend framework connection with Twitter (Oauth)’

Post to Twitter