Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-8 Problem, no Idea

I have a strange problem with some documents on my webpage.

My data is stored in a MYSQL Database, UTF8 encoded. If read the values my webbpage displays

Rezept : Gem�se mal anders (Gem�selaibchen)

I need ü / ü!

Content in the database is "Gemüse ... " ..

The raw data in my error_log looks like this

[title] => Rezept : Gemüse mal anders (Gemüselaibchen)

The webpage header is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<!--[if IE]>
  <link rel="stylesheet" href="http://www.dev-twitter-gewitter.com/css//blueprint/ie.css" 
        type="text/css" media="screen, projection">
<![endif]-->

<meta name="text/html; charset=UTF-8" content="Content-Type" />
like image 974
opHASnoNAME Avatar asked Jul 05 '09 06:07

opHASnoNAME


1 Answers

You have to set the encoding of your web page.

There are three ways to set the encoding:

  1. HTML/XHTML: Use a HTTP header:

    Content-Type: text/html; charset=UTF-8
    
  2. HTML: Use a meta element: (Also possible for XHTML, but somewhat unusually)

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
  3. XHTML only: Set the encoding in the preamble: (Preferred for XHTML)

    <?xml version="1.0" encoding="UTF-8"?>
    

If you want to verify the problem first:

First change the encoding manually using your browser. If that works you can set it in your HTML file. Make sure you reset the manual encoding to automatic detection, otherwise it'll work on your workstation, but not on your users' workstations!

A PHP speciality: Make sure your internal encoding is set to UTF-8, too! All outputs are converted to this encoding.

You can enforce the internal encoding using mb_internal_encoding at the top of every file.

After all: All this doesn't help if your code isn't actually UTF-8 encoded! If it is, check if there are any helper functions which might destroy the UTF-8 encoding.

like image 183
Daniel Rikowski Avatar answered Oct 04 '22 22:10

Daniel Rikowski