Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle character sets properly in conjunction with a database, text areas etc etc
    primarykey
    data
    text
    <p>For once and for all I want to have clear how to handle ü etc in my application. I understand using UTF-8 is the best way to store/represent these strange characters. </p> <p>So I declare in my HTML a meta-charset:</p> <pre><code>&lt;meta charset="utf-8"&gt; </code></pre> <p>Storing the content in my database, it also needs the right set so I set the collation to <code>utf8_general_ci</code></p> <p><img src="https://i.stack.imgur.com/U7RnT.png" alt="unicode"></p> <p>In my understanding there isn't an other place where I can define the character set. But what is the problem?</p> <p>If I go into phpMyAdmin and add jülich in the content field, and I subtract the content from the database through a mysql query and PHP. The ü gets displayed properly. But if I view it in a Textarea it displays a black diamond shaped figure with a white ? in it.</p> <p>If I put in the text in a textarea in my application and submit it, it displays correct in the text area. But on the website it displays ü</p> <p>These are the charset settings in the startup screen of phpMyAdmin: <img src="https://i.stack.imgur.com/cdoOt.png" alt="phpMyadmin"></p> <p>As an answer on questions off Daan:</p> <p>character%:</p> <p><img src="https://i.stack.imgur.com/5Lf09.png" alt="phpMyadmin"></p> <pre><code>character_set_client = utf8 character_set_connection = utf8 character_set_database = utf8 character_set_filesystem = binary character_set_results = utf8 character_set_server = latin1 character_set_system = utf8 character_sets_dir = /usr/share/mysql/charsets/ </code></pre> <p>collation% </p> <p><img src="https://i.stack.imgur.com/LTYf5.png" alt="phpMyadmin"></p> <pre><code>collation_connection = utf8_general_ci collation_database = utf8_general_ci collation_server = latin1_swedish_ci </code></pre> <p>How can I resolve this?</p> <p><strong>Things I've done so far:</strong></p> <p>added: <code>header('Content-type: text/html; charset=utf-8');</code></p> <p>added: <code>$this-&gt;db-&gt;setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");</code></p> <p>added: <code>&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;</code></p> <p>added: <code>$this-&gt;db = new PDO($dsn, $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES utf8"));</code></p> <p><strong>Solution</strong></p> <p>All the above is working like a charm. But if you use a function to replace certain special routines and return the replaced string through <code>utf8_decode()</code> it obviously doesn't display the ü ;(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload