我正在php中建立一个简单的博客模型,因为现在我已经将这些数据直接添加到phpmy admin的数据中,这是虚拟数据。
Post-ironic mumblecore authentic, stumptown try-hard chambray sartorial
McSweeney’s VHS put a bird on it. Pitchfork lomo meggings, meh whatever cred
beard four loko hella. Flannel swag normcore, leggings 3 wolf moon meditation
Marfa hella fingerstache Thundercats mustache. Lo-fi typewriter Shoreditch,
Odd Future fingerstache iPhone retro McSweeney’s four loko Kickstarter hoodie上面的文本中有'单引号值,现在的问题是,当vales被解析为php,然后以HTML格式显示时,它显示的是�而不是单引号。
有什么问题吗?
这是我正在以html格式获取的输出。
Post-ironic mumblecore authentic, stumptown try-hard chambray sartorial
McSweeney�s VHS put a bird on it. Pitchfork lomo meggings, meh whatever
cred beard four loko hella. Flannel swag normcore, leggings 3 wolf moon
meditation Marfa hella fingerstache Thundercats mustache. Lo-fi typewriter
Shoreditch, Odd Future fingerstache iPhone retro McSweeney�s four loko
Kickstarter hoodie我正在使用普通的php代码来显示类似于这个<?php echo $value['post_content']; ?>的数据,我甚至在PHP中尝试过htmlspecialchars_decode函数,但是不能很好地工作
我使用的是面向对象的PHP技术,这是我使用的代码
$query = "SELECT * FROM posts";
$connection = $this->establish_connection();
$data = $connection->query($query);
$connection->close();发布于 2017-10-01 18:32:14
这是一个Unicode问题。
原始文本使用不同的Unicode编码,而不是用于显示(utf8),因此,请尝试如下:
$query = "SELECT * FROM posts";
$connection = $this->establish_connection();
$connection->set_charset("utf8");
$data = $connection->query($query);
$connection->close();发布于 2017-10-01 18:34:09
我不认为你的逗号是标准单引号。将它们转换为它们的数字表示,并将其与标准单引号进行比较,就清楚地表明了这一点。
尝试以下操作:要么用标准单引号替换所有这些逗号,要么将现有逗号转换为相应的HTML实体或unicode表示。如果您转换它们,然后在不同的浏览器上测试它们,以确保跨兼容性。
发布于 2017-10-01 18:38:38
您需要在html的头标记中设置与db中数据的编码相匹配的元编码,例如:
<meta charset="UTF-8">
与文件和数据库中的编码匹配是很重要的。您可以在大多数文本编辑器中使用工具保存和编码,并在数据库中设置表字段的编码。
https://stackoverflow.com/questions/46515356
复制相似问题