我有一个简单的数据库,其中有旅行的旅行描述。在数据库中,行程描述包括撇号和输入/返回,其类型为:文本。
我想检索所有旅行描述(有很多)并将其回显到网站上,但是撇号、连字符和其他特殊字符正在变成 � 而输入/返回则不是那里。
例如数据库中的以下文本:
We'll arrive in New Georgia to paddle around the famous Marovo Lagoon - the world's largest salt water lagoon - for seven days.
We will return to...
在网页上显示为
We'll arrive in New Georgia to paddle around the famous Marovo Lagoon � the world�s largest salt water lagoon � for seven days. We will return to...
“我们将返回...”不在新段落中,撇号和两个连字符是 �
这是我的 php 代码:
$tripResult = mysql_query("SELECT * FROM trips");
while($row = mysql_fetch_array($tripResult)){
echo $row['tripDescription'];
}
我尝试用替换 echo 线
echo htmlspecialchars($row['tripDescription'], ENT_QUOTES);
但这根本不显示任何文本。
编辑:我还尝试检查我是否有字符集元标记,将数据库排序规则更改为 utf8mb4_general_ci (我可以在下拉列表中找到的最接近 utf8mb4 的排序规则),并替换 echo与:
echo mysql_set_charset($row["tripDescription"]);
但是它仍然根本不显示任何文本。我怎样才能让这段文字看起来正常?
最佳答案
使用addslashes — Quote string with slashes插入您的数据并开始使用stripslashes .
$tripResult = mysql_query("SELECT * FROM trips");
while($row = mysql_fetch_array($tripResult)){
echo stripslashes($row['tripDescription']);
}
关于php - 如何从数据库中回显回车符和撇号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38112337/