Encoding issues for php and mysql

I'm having encoding issues with my LAMP stack.

The web page head has:

My PDO dsn is: mysql:host=localhost;dbname=$database;charset=utf8

The options array is:

options = array (

I've tried both with and without setting PDO::MYSQL_ATTR_INIT_COMMAND; I get the same results either way.

I retrieve from my db with something like:

$sql = 'SELECT * FROM ...';
$prepared = $dbh->prepare($sql);
while ($row = $prepared->fetch(PDO::FETCH_ASSOC)) {

There are no bound parameters.

The collation for the database, all the tables, and all the string (CHAR, VARCHAR, TEXT) collumns is utf8_unicode_ci.

If I have (for example) 18”x24” in my database (as inserted by phpMyAdmin), I get 18”x24” in input and textarea fields but 18�x24� when echoed outside a form.

If I have 18â€x24†in my db, I get 18â€x24†in input and textarea fields but 18”x24” when echoed outside a form.

How do I get 18”x24” (not 18�x24� and not 18â€x24â€) to display both inside and outside form fields?


I have discovered that I badly misdescribed my problem. For example, the inside v. outside form fields part was wrong.

The MySql data was not really UTF-8. I had to fix the data, not the php coding.

Need Your Help

HTTP Post from Console application C#

c# console httpwebrequest

I have web site that contains textbox and button, when enter something in the textbox and click the button the site redirect to another one.

Setting up RoadKill

wiki roadkill-wiki

I am trying to setup a internal wiki site for project documentation project. I am using roadkill because I have a IIS server and a .net environment.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.