Carachters converted to <?>!

Hello,

I have a PHP/ MYSQL driven content website in which I have alot of latin characters in the MySQL Tables…

Now in PHPMYADMIN the characters show up fine…But on my website My characters are converted into <?> in my web pages.

I have converted all my files to utf-8… still no luck.

Can anyone please help?

Many thanks,
MDiogo

Immerse, i’m on my way, I got it fixed using the query you provided, I also changed the way I’m connecting to something more clear on the code.

Many thks Mário.

Check in your browser, what does it say the character encoding is?

In Firefox: View -> Character Encoding

If that’s not what you expect (I think utf8?) then you may need to send some additional headers to get the browser to use the correct encoding.

For PHP, something like this should work:


header('Content-Type: text/html; charset=UTF-8');

Hi, my Character Encoding seems to be the correct, Unicode UTF-8. Still some characters appear has ��

Can’t find the cause for this, any more help or something you could remember would be great.

OK, next step is to check the collation of the database.

Before you retrieve your data, try executing this query:


SET NAMES utf8;

Hello Immerse, I have executed the query at phpMyAdmin, no luck, everything stays the same.

No, you need to do this in your PHP application.

Whenever you create a new connection to the database, you should execute that query.

For example:


$conn = mysql_connect('host', 'user', 'pass');
mysql_query('SET NAMES utf8', $conn);

Hello again Immerse, thanks for the support. I have made that change but gives me an error, I believe I am making some sintax mistake.

This is how i’m doing my connection:


<?php
$dbname="*****"; // Indique o nome do banco de dados que será aberto   
$usuario="*****"; // Indique o nome do usuário que tem acesso
$passsql="*****"; // Indique a senha do usuário
foreach($_POST AS $key => $value) { ${$key} = $value; }
foreach($_REQUEST AS $key => $value) { ${$key} = $value; }
function res($id,$sql,$erro = 1) {
    if(empty($sql) OR !($id))
       return 0; //Erro na conexão ou no comando SQL
   if (!($res = @mysql_query($sql,$id))) { if($erro)
        echo "Ocorreu um erro na execução do Comando SQL no banco de dados. Favor Contactar o Administrador.<br>QUERY: $sql";
      exit;} return $res;}
if(!($id = mysql_connect($_ENV{DATABASE_SERVER},$usuario,$passsql))) {
   echo "Não foi possível estabelecer uma conexão com o gerenciador MySQL. Favor Contactar o Administrador.";
   exit;
}
//2º passo - Seleciona o Banco de Dados
if(!($con=mysql_select_db($dbname,$id))) {
   echo "Não foi possível estabelecer uma conexão com o gerenciador MySQL. Favor Contactar o Administrador.";
   exit;
}
?>

Can you kindly show me how can I make that change on the script?

Can’t this script be a little more clear?

Many thks,
Mário