Thursday, September 06, 2007

MySQL + PHP + UTF-8 = ????

The title is not a question. It actually describes a common problem: i.e., when UTF-8 characters stored in MySQL is queried through PHP
they displayed as question marks on the web page. The solution (courtesy of Shawn Olson) is call this before any of your database manipulation code:

mysql_query("SET NAMES 'utf8'");

BTW, I host my site and MySQL database at GoDaddy and it supports UTF-8 "out of the box" without any special config.

How to implement a hyperlink that "Save File As Target"

This is useful for linking to media file when you want your user to download the whole file before playing instead of opening the media player and "progressive download", i.e, buffer some and play right away before download is completed. Most modern browser and media player work well together in this regards and the former is an option from
right-mouse-click but I got a requirement to do this from left-mouse-click from my dad (No, right-mouse-click is not user-friendly enough according to my "customer")! So I found this solution in PHP.