简体   繁体   中英

All special characters are question marks in PHP/HTML

Php default character set is UTF-8. All special characters in PHP and HTML are outputting as question mark like "?" in the browser. All data with special characters are stored as UTF-8 in database fields. But when PHP reads the database and output to browsers, all special characters like copyright and trademark symbols are ?

Data cannot be encoding as htmlentities, because otherwise data wouldve been outputted in the browser as html code. The fields in the database have html markups. It's like a wysiwyg field.

The other similiar question didn't really solve the problem. My problem is that php is reading a database field encoded in utf-8 including html markup, text and special characters. Then save the data in another utf-8 encoded database field. But something in the middle isn't right. After the process is done, special characters in new mysql columns are ?. Thus browser is displaying ? for all special characters.

$conn = new mysqli($host, $username, $password, $dbName);
mysql_set_charset('utf-8',$conn);


$categoryDescription = utf8_encode(utf8_decode($var['manufacturer_overview']));

I had similar problem

But can be caused because of multiple reason .

1.Check if header has

<meta charset="utf-8" />

2.Open the pages that contains Special char-set only in the Editor that supports them

3.This is what happend in my case

I was saving the data in DB using php function utf8_encode() but also in the database In my execute function it was already present

mysql_set_charset('utf8',$dbSelect);

My function looks like this

public function execute($sql,$useDb = 1)
    {
        if($useDb == static::LOCAL)
        {
            $dbSelect = $this->conexion;
        }elseif ($useDb == static::REMOTE) 
        {
            $dbSelect = $this->paisConexion;
        }
        mysql_set_charset('utf8',$dbSelect);
        $result = mysql_query($sql,$dbSelect) or die("ERROR: Ejecuci&oacute;n de consulta: $sql<br>\n");

        return $result;
    }

So it was being encoded twice I removed one and now it works fine.

Hope any of these helps

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM