Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MySQL with encoding problems
    primarykey
    data
    text
    <p>I am having trouble with PHP regarding encoding.</p> <p>I have a JavaScript/jQuery HTML5 page interact with my PHP script using $.post. However, PHP is facing a weird problem, probably related to encoding.</p> <p>When I write</p> <pre><code>htmlentities("í") </code></pre> <p>I expect PHP to output <code>&amp;iacute;</code>. However, instead it outputs <code>&amp;Atilde;&amp;shy;</code> At the beginning, I thought that I was making some mistake with the encodings, however</p> <pre><code>htmlentities("í")=="&amp;iacute;"?"Good":"Fail"; </code></pre> <p>is outputing "Fail", where</p> <pre><code>htmlentities("í")=="&amp;Atilde;&amp;shy;"?"Good":"Fail"; </code></pre> <p>But <code>htmlentities($search, null, "utf-8")</code> works as expected.</p> <p>I want to have PHP communicate with a MySQL server, but it has encoding problems too, even if I use utf8_encode. What should I do?</p> <p>EDIT: On the SQL command, writing</p> <pre><code>SELECT id,uid,type,value FROM users,profile WHERE uid=id AND type='name' AND value='XXX'; </code></pre> <p>where XXX contains no í chars, works as expected, but it does not if there is any 'í' char.</p> <pre><code>SET NAMES 'utf8'; SET CHARACTER SET 'utf8'; SELECT id,uid,type,value FROM users,profile WHERE uid=id AND type='name' AND value='XXX'; </code></pre> <p>Not only fails for í chars, but it ALSO fails for strings without any 'special' characters. Removing the ' chars from SET NAMES and SET CHARACTER SET doesn't seem to change anything.</p> <p>I am connecting to the MySQL database using PDO.</p> <p>EDIT 2: I am using MySQL version 5.1.30 of XAMPP for Linux.</p> <p>EDIT 3: Running <code>SHOW VARIABLES LIKE '%character%'</code> from PhpMyAdmin outputs</p> <pre><code>character_set_client utf8 character_set_connection utf8 character_set_database latin1 character_set_filesystem binary character_set_results utf8 character_set_server latin1 character_set_system utf8 character_sets_dir /opt/lampp/share/mysql/charsets/ </code></pre> <p>Running the same query from my PHP script(with print_r) outputs:</p> <pre><code>Array ( [0] =&gt; Array ( [Variable_name] =&gt; character_set_client [0] =&gt; character_set_client [Value] =&gt; latin1 [1] =&gt; latin1 ) [1] =&gt; Array ( [Variable_name] =&gt; character_set_connection [0] =&gt; character_set_connection [Value] =&gt; latin1 [1] =&gt; latin1 ) [2] =&gt; Array ( [Variable_name] =&gt; character_set_database [0] =&gt; character_set_database [Value] =&gt; latin1 [1] =&gt; latin1 ) [3] =&gt; Array ( [Variable_name] =&gt; character_set_filesystem [0] =&gt; character_set_filesystem [Value] =&gt; binary [1] =&gt; binary ) [4] =&gt; Array ( [Variable_name] =&gt; character_set_results [0] =&gt; character_set_results [Value] =&gt; latin1 [1] =&gt; latin1 ) [5] =&gt; Array ( [Variable_name] =&gt; character_set_server [0] =&gt; character_set_server [Value] =&gt; latin1 [1] =&gt; latin1 ) [6] =&gt; Array ( [Variable_name] =&gt; character_set_system [0] =&gt; character_set_system [Value] =&gt; utf8 [1] =&gt; utf8 ) [7] =&gt; Array ( [Variable_name] =&gt; character_sets_dir [0] =&gt; character_sets_dir [Value] =&gt; /opt/lampp/share/mysql/charsets/ [1] =&gt; /opt/lampp/share/mysql/charsets/ ) ) </code></pre> <p>Running</p> <pre><code>SET NAMES 'utf8'; SET CHARACTER SET 'utf8'; SHOW VARIABLES LIKE '%character%' </code></pre> <p>outputs an empty array.</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.
 

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