Jump to content

Character Sets not working? Please advise


Perad

Recommended Posts

Hello,

 

Having a torrid time here. The site is Portuguese.

 

The MySQL character set is ut8, the collation is ut8_general_ci

 

In the database i have this word. 'MATENÇÃO'.

 

It appears correctly in phpMyAdmin

 

When it outputs to the webpage it becomes distorted.

 

There are several things which I do not understand here.

 

If I write this page into my default template file. (main_page.php) it works. It displays fine.

 

If I write this word into my header file (header.php), it becomes distorted.

 

If I echo this word instead of calling it from the database it displays correctly.

 

The page in question can found here. 69.89.31.108/~nortavia/ntv/

 

Please check the various comments above the page, in the nav menu and below the menu.

 

Do you have any idea what is going on?

Link to comment
Share on other sites

First of all, you're setting the wrong charset in your HTML meta tag:

 

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

 

It should be:

 

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

 

And a second thing; when connecting to your database, you'll have to set names and character set to UTF-8 in MySQL:

 

<?php
//connect to DB
$connection = mysql_connect($db_host, $db_user, $db_pass) or die('Error connecting to database.');
//select DB
mysql_select_db($db_name, $connection) or die('Error selecting database.');
//set names and character set to UTF-8
mysql_query("SET NAMES 'utf8'", $connection);
mysql_query('SET CHARACTER SET utf8', $connection);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.