I'm having trouble with PHP regarding coding.
I have an HTML / jQuery HTML5 JavaScript page that interacts with my PHP script using $ .post. However, PHP is facing a strange problem, probably related to the encoding.
When I write
htmlentities("í")
I expect PHP to output í . However, instead, it prints í At first I thought I was wrong in the encodings, however
htmlentities("í")=="í"?"Good":"Fail";
displays "fail" where
htmlentities("í")=="í"?"Good":"Fail";
But htmlentities($search, null, "utf-8") works as expected.
I want PHP to communicate with the MySQL server, but it also has encoding problems, even if I use utf8_encode. What should I do?
EDIT: In SQL command write
SELECT id,uid,type,value FROM users,profile WHERE uid=id AND type='name' AND value='XXX';
where XXX contains no characters, it works as expected, but it is not, if there is any 'í' char.
SET NAMES 'utf8'; SET CHARACTER SET 'utf8'; SELECT id,uid,type,value FROM users,profile WHERE uid=id AND type='name' AND value='XXX';
Not only fails for characters, but it also doesn't work for strings without any special characters. Removing "characters from SET NAMES and SET CHARACTER SET" does not seem to change anything.
I am connecting to a MySQL database using PDO.
EDIT 2: I am using MySQL version 5.1.30 XAMPP for Linux.
EDIT 3: Launch SHOW VARIABLES LIKE '%character%' from PhpMyAdmin Outputs
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/
Running the same request from my PHP script output (with print_r):
Array ( [0] => Array ( [Variable_name] => character_set_client [0] => character_set_client [Value] => latin1 [1] => latin1 ) [1] => Array ( [Variable_name] => character_set_connection [0] => character_set_connection [Value] => latin1 [1] => latin1 ) [2] => Array ( [Variable_name] => character_set_database [0] => character_set_database [Value] => latin1 [1] => latin1 ) [3] => Array ( [Variable_name] => character_set_filesystem [0] => character_set_filesystem [Value] => binary [1] => binary ) [4] => Array ( [Variable_name] => character_set_results [0] => character_set_results [Value] => latin1 [1] => latin1 ) [5] => Array ( [Variable_name] => character_set_server [0] => character_set_server [Value] => latin1 [1] => latin1 ) [6] => Array ( [Variable_name] => character_set_system [0] => character_set_system [Value] => utf8 [1] => utf8 ) [7] => Array ( [Variable_name] => character_sets_dir [0] => character_sets_dir [Value] => /opt/lampp/share/mysql/charsets/ [1] => /opt/lampp/share/mysql/charsets/ ) )
Launch
SET NAMES 'utf8'; SET CHARACTER SET 'utf8'; SHOW VARIABLES LIKE '%character%'
prints an empty array.