简体   繁体   English

所有特殊字符都是PHP / HTML中的问号

[英]All special characters are question marks in PHP/HTML

Php default character set is UTF-8. Php默认字符集是UTF-8。 All special characters in PHP and HTML are outputting as question mark like "?" PHP和HTML中的所有特殊字符都输出为问号“?” in the browser. 在浏览器中。 All data with special characters are stored as UTF-8 in database fields. 具有特殊字符的所有数据都以UTF-8格式存储在数据库字段中。 But when PHP reads the database and output to browsers, all special characters like copyright and trademark symbols are ? 但是当PHP读取数据库并输出到浏览器时,所有特殊字符如版权和商标符号都是?

Data cannot be encoding as htmlentities, because otherwise data wouldve been outputted in the browser as html code. 数据不能编码为htmlentities,因为否则数据将作为html代码在浏览器中输出。 The fields in the database have html markups. 数据库中的字段具有html标记。 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. 我的问题是php正在读取以utf-8编码的数据库字段,包括html标记,文本和特殊字符。 Then save the data in another utf-8 encoded database field. 然后将数据保存在另一个utf-8编码的数据库字段中。 But something in the middle isn't right. 但中间的事情是不对的。 After the process is done, special characters in new mysql columns are ?. 完成此过程后,新mysql列中的特殊字符是?。 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 1.检查标题是否有

<meta charset="utf-8" />

2.Open the pages that contains Special char-set only in the Editor that supports them 2.仅在支持它们的编辑器中打开包含特殊字符集的页面

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 我使用php函数utf8_encode()保存数据库,但也在数据库中我的执行函数中它已经存在

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 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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