MySQL returning garbage characters – encoding issue

posted in: Technology | 0

If your database has special UTF-8 characters like the trademark, copyright etc but your script is returning them to the browser as garbage characters, do the following:

  1. Make sure the database table columns are stored using utf8_general_ci encoding
  2. The HTML page should have the following header:
    <meta charset=”utf-8″ />
  3. Add the following as your first query after connecting to MySQL:
    mysql_query("SET NAMES UTF8");