Problems with UTF-8 ISO-8859-1 mysql php accent [duplicate]

2

I'm having trouble with PHP / Mysql

When I use:

header("Content-Type: text/html; charset=UTF-8",true);
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

The HTML code is ok, but MySQL results with emphasis .

If I change to:

header("Content-Type: text/html; charset=ISO-8859-1",true);
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

The problem reverses, the results of the bank are ok and html is:

Next (ex: Next)

I changed the database to Latin1 and returned to UTF-8 and nothing. I've tried utf8_encode (), htmlentities () and it's still the same.

Any suggestions?

    
asked by anonymous 13.12.2017 / 13:17

2 answers

1

If your database is coded differently than your code you can use example in PHP:

mysql_query("SET character_set_results = 'utf8'");

Replace 'utf8' for your preferred encoding. But the ideal thing is to analyze if your code files and the database are with the standard coding so you will not have these problems.

    
13.12.2017 / 13:36
2

On your connection, use set_charset:

$connMysql = mysql_connect('localhost', $myUser, $myPass);
mysql_select_db($database, $connMysql);
mysql_set_charset('UTF8');
    
13.12.2017 / 13:35