Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a couple things that might help. First, even though you're setting the charset to UTF-8 in the header, that might not be enough. I've seen the browser ignore that before. Try forcing it by adding this in the head of your html:</p> <pre><code>&lt;meta charset='utf-8'&gt; </code></pre> <p>Next, as mentioned <a href="https://stackoverflow.com/questions/2446778/how-to-display-unicode-data-with-php#answer-2446818">here</a>, try doing this:</p> <pre><code>mysql_query ("set character_set_client='utf8'"); mysql_query ("set character_set_results='utf8'"); mysql_query ("set collation_connection='utf8_general_ci'"); </code></pre> <p><strong>EDIT</strong></p> <p>So I've just done some reading up an playing around a bit. First let me tell you, despite what I mentioned in the comments, <code>utf8_encode()</code> and <code>utf8_decode()</code> will not help you here. It helps to actually understand UTF-8 encoding. I found the Wikipedia page on <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow noreferrer">UTF-8</a> very helpful. Assuming the value you are getting back from the database is in fact already UTF-8 encoded and you simply dump it out right after getting it then it should be fine.</p> <p>If you are doing anything with the database result (manipulating the string in any way especially) and you don't use the unicode aware functions from the PHP <a href="http://php.net/manual/en/book.mbstring.php" rel="nofollow noreferrer">mbstring</a> library then it will probably mess it up since the standard PHP string functions are not unicode aware.</p> <p>Once you understand how UTF-8 encoding works you can do something cool like this:</p> <pre><code>$test = "™"; for($i = 0; $i &lt; strlen($test); $i++) { echo sprintf("%b ", ord($test[$i])); } </code></pre> <p>Which dumps out something like this:</p> <pre><code>11100010 10000100 10100010 </code></pre> <p>That's a properly encoded UTF-8 '™' character. If you don't have a character like that in your data retrieved from the database then something is messed up.</p> <p>To check, try searching for a special character that you know is in the result using <code>mb_strpos()</code>:</p> <pre><code>var_dump(mb_strpos($db_result, '™')); </code></pre> <p>If that returns anything other than <code>false</code> then the data from the database is fine, otherwise we can at least establish that it's a problem between PHP and the database.</p>
 

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