在数据库表中,列name是varchar(255)列上的编码:utf8_unicode_ci列中的示例值:Garner Heating & Cooling当我查询这个值时,使用:$conn = new mysqli($host, $user, $pw, $db);$sql = "SELECT id,name FROM bizs WHERE name = 'Garner Heating & Cooling'";if ($result = $conn->query($sql)) { if ($conn->affected_rows > 0) { while ($row = $result->fetch_assoc()) { echo "OLD Name: " . $row['name'] . "\n"; } }}输出: OLD Name: Garner Heating & Cooling为什么&被转换为&?
2 回答
倚天杖
TA贡献1828条经验 获得超3个赞
使用这一行来查看相同的编码数据:
echo "OLD Name: " . htmlentities($row['name'], ENT_QUOTES) . "\n";
红颜莎娜
TA贡献1842条经验 获得超12个赞
您应该使用 htmlentities 功能:
$conn = new mysqli($host, $user, $pw, $db);
$sql = "SELECT id,name FROM bizs WHERE name = 'Garner Heating & Cooling'";
if ($result = $conn->query($sql)) {
if ($conn->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "OLD Name: " . htmlentities($row['name'], ENT_QUOTES) . "\n";
}
}
}
- 2 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消