Search code examples
mysqlutf-8character-encodinglocalhostidiorm

PHP utf8 with idiorm and mysql


I use WAMP to run PHP code on localhost. The problem is that on my localhost I get utf8 errors like "lÃ¥n". On the live server I get "lån" like suspected.

What I've tried so far

  • Set database table on server and localhost to utf8_general_ci
  • Set database table structure rows on server and localhost to utf8_general_ci
  • Checked file encoding with utf cast, they are set ASCII/UTF-8, NO BOM on both server and localhost
  • Forced PHP header with header('Content-Type: text/html; charset=utf-8');
  • Forced UTF8 to database with ORM::configure('mysql:host=SECRET;dbname=SECRET;charset=utf8');
  • Added ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); with no luck

More info

  • The data are identical in the database when I use phpmyadmin. I even used a diff tool.
  • The data are not identical on output. Why not? What to do?
  • I use idiorm for nice SQL.
  • The databases settings are the same.
  • The files are the same. I upload them to the server.
  • I have filezilla to send them as binary.

I just want the localhost and the server to show the same, without if statement workaround. I don't want utf8_decode on one place and not on the other.

Any ideas what I can try?


Solution

  • I don't know why but I had to put $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); before @$dom->loadHTML($html); that I have in my code.

    I still don't know why it doesn't work without it when localhost and server settings are equal in every way.