Question

I am having a strange problem in that when anything from my mysql database is retrieved and echo'd out in a php script the quotation marks in the record are being replaced by diamond shaped question marks in Google Chrome.

My mysql database is set to collation : utf8_general_ci

The part of script that is pulling down the records is as follows :

    <?php
    echo '<div class="testimonialswrapper">';
    // Retrieve Page Content //
     $testimonialssql = <<<SQL
        SELECT *
        FROM `testimonials`
        ORDER BY id DESC
        LIMIT 5
    SQL;

    if(!$resulttestimonials = $db->query($testimonialssql)){
        die('There was an error running the query [' . $db->error . ']');
    }
    while($rowT = $resulttestimonials->fetch_assoc()){
        if ($rowT['company'] == ''){$name = $rowT['name'];}else{$name = $rowT['name'].' - '.$rowT['company'];}
        $from = $rowT['from'];
        $message = $rowT['message'];
        echo '<p class="testititle">'.$name.'</p>';
        echo '<p class="testifrom">'.$from.'</p>';
        echo '<p class="testimessage">'.$message.'</p>';
            }
            echo '</div>';
    ?>

This is included in my index.php which has the following settings :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I have tried using htmlenteties and stripslashes and various other things, but still have the same problem.

Was it helpful?

Solution

If you see the UNICODE REPLACEMENT CHARACTER �, that means your browser is trying to read text in a Unicode encoding, but the encountered value is not actually encoded in a valid Unicode encoding and has hence been replaced as undecodable.

This means the data from your database is not actually UTF-8 encoded, as you claim in your meta tag. You likely have curly quotes encoded in Latin-1 there. See UTF-8 all the way through my web application (Apache, MySQL, PHP, …) and Handling Unicode Front To Back In A Web App.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top