5

I've done everything I can think of, but special characters are not displaying correctly on this webpage.

For example, in the database it's:

enter image description here

But on the site it's:

Nouveaux R�alistes

Here's everything I've checked...

The database is set to UTF-8:

enter image description here

The page was written in NetBeans, with the document encoding set to UTF-8:

enter image description here

The page header declares UTF-8:

enter image description here

The meta charset is set to UTF-8:

enter image description here

I've even added the following line to my .htacess:

enter image description here

But there characters are still not displaying correctly, and I get the following error from the W3C Validator:

enter image description here

I feel like I've attempted everything, but it still won't work. (I've even tried htmlspecialchars and htmlentities in PHP, but the page doesn't even render!)


UPDATE
As requested, here is the code I'm using:

class Exhibition {
    public $exhibitionDetails;    

    public function __construct(Database $db, $exhibitionID){
        $this->_db = $db;

        $params['ExhibitionID'] = $exhibitionID;

        $STH = $this->_db->prepare("SELECT * 
            FROM Exhibition
            INNER JOIN Schedule
                ON Exhibition.ExhibitionID = Schedule.ExhibitionID            
            WHERE Schedule.Visible = 1
                AND Exhibition.ExhibitionID = :ExhibitionID;");

        $STH->execute($params);

        $this->exhibitionDetails = $STH->fetchAll(PDO::FETCH_ASSOC);

    }
}

And...

try {
    $db = new Database(SITE_ROOT."/../");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $exhibition = new Exhibition($db,$_GET['id']);
} catch (PDOException $e) {
    echo "<p class='error'>ERROR: ".$e->getMessage()."</p>";
}

And finally...

<p><?php echo $exhibition->exhibitionDetails[0]["Desc"]; ?></p>
Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
  • I guess you just encoding too much. Can you show your php code which fetches the records and output it? – hek2mgl Apr 18 '13 at 20:30
  • 1
    What font are you using? I had a similar issue with a pdf. [See here](http://stackoverflow.com/questions/15787001/accented-character-showing-as-in-a-pdf-using-persits-pdf) – Jack Pettinger Apr 18 '13 at 20:30
  • It seems that your data in the database is not encoded in UTF-8. – Gumbo Apr 18 '13 at 20:31
  • @Gumbo I've pasted the data into a UTF-8 encoded document in NetBeans. Saved it, closed it, reopened it, and checked the text. It looked good, so I cut and pasted it back into the database... but still the same result. Do you have any recommendations? – Chuck Le Butt Apr 18 '13 at 20:58
  • How do you insert the data into the database? – Gumbo Apr 18 '13 at 21:06
  • @Gumbo It was my database connection encoding, exactly as IAmNotProcrastinating predicted. Hurrah! – Chuck Le Butt Apr 18 '13 at 21:11

2 Answers2

4

If you are using mysql_* functions:

mysql_query("SET NAMES 'utf8'");

If you are using PDO

$dsn = 'mysql:host=localhost;dbname=testdb';
$username = 'username';
$password = 'password';
$options = array(
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
); 

$dbh = new PDO($dsn, $username, $password, $options);

It sets connection encoding.

1

It's been a few years since I've used PHP but back then it didn't natively support Unicode and a quick search of google tells me it still doesn't. You can still make it work though.

Here's a great link:

Encodings And Character Sets To Work With Text

Captain Skyhawk
  • 3,499
  • 2
  • 25
  • 39