php - 回显字符串并不总是显示单个引号
问题描述
我有一个网站(链接),其中用户故事显示在从 MySql 数据库获取的屏幕上。我的问题是,撇号并不总是显示在最后呈现的数据中。我使用htmlentities($row['MessageText'],ENT_COMPAT|ENT_IGNORE, "UTF-8")
然后echo json_encode($data)
.
下面的例子没有撇号(所以它是它,我是我):
听起来很疯狂,但这就是一切;家庭,工作,人们对我的看法。如果我坐着更糟,这就是为什么我总是很忙
var_dump:
array(5) { ["ID"]=> int(65) ["UserIDLikeChk"]=> string(1) "0" ["MessageText"]=> string(1263) "Sounds crazy, but it�s everything; home, work, what people think of me. If I sit still its worse, that�s why I�m always busy, always moving. Its things in my head that are out of my control. I can but quite irrational, like the worst thing is going to happen and it gets worse when I�m tired. When I�m exhausted I get irrational. When I was young I got panic attacks. I can control them now, but when I came back from Orlando recently, I was very tired and I could feel I was spiralling down a bit, like a panic attack was coming. When that happens all I can see is what is in my head and no one can talk sense to me. I can have a period of a couple of weeks, where I can feel the anxiety underlying, a knot in my stomach and I know if I�m not careful I could have a panic attack. I�m not a very confident person, so that makes the worry worse I think. I try to rationalise things and that makes things better. I use the Calm app, I speak to my mum, I remove myself from people and that calms me down. I also go to the gym to get the kick from the endorphins. I also avoid alcohol now because that makes things much worse. I think I was drinking after the Orlando trip, when I was really tired, I had a heavy night when I went out, and that made it so much worse." ["CntLikes"]=> int(0) ["Type"]=> int(0) }
代码:
$userid = session_id();
$stmt = $con->prepare(
'SELECT
a.ID, ? as UserID, IFNULL(b.UserID,0) as UserIDLikeChk, a.MessageText, a.CntLikes, IFNULL(b.Type,0) as Type
FROM
(
SELECT m.ID, m.MessageText,count(l.ID) as CntLikes
FROM MessageMain m
LEFT OUTER JOIN Likes l ON m.ID = l.PostID
WHERE Valid = 1
GROUP BY m.ID, m.MessageText ORDER BY RAND() LIMIT 10
)a
LEFT OUTER JOIN
(
SELECT PostID, UserID, COUNT(*) AS Type
FROM Likes
WHERE UserID = ?
GROUP BY PostID, UserID
)b
ON a.ID = b.PostID'
);
$stmt->bind_param('ss', $userid, $userid);
$stmt->execute();
$result = $stmt->get_result();
$data = array();
if(mysqli_num_rows($result) > 0) {
While($row = $result->fetch_assoc()) {
$data[] = array (
'ID' => $row['ID'],
'UserID' => $row['UserID'],
'UserIDLikeChk' => $row['UserIDLikeChk'],
'MessageText' => nl2br(htmlentities($row['MessageText'],ENT_COMPAT|ENT_IGNORE, "UTF-8") ),
'CntLikes' => $row['CntLikes'],
'Type' => $row['Type']
);
}
}
echo json_encode($data);
解决方案
推荐阅读
- python - 在 python Pandas 中将对象转换为时间
- node.js - 这个包已被弃用,现在它只导出 makeExecutableSchema
- function - Kivy 多个切换按钮都在一个函数中读取
- javascript - 如何提交我的文本框值以转到 React js 中的链接?
- java - 如何在 Firebase Firestore 中获取随机文档
- c - 调试 vscode 的问题以及对 C 中引用调用的一些误解
- javascript - 在保留方法的同时将深度嵌套的类对象转换为普通对象?
- python - 如何检查自上次循环以来是否已经过了足够的时间?
- angular - 为什么 Angular 布局不能正常工作?
- android - 在显示从 Firestore 获取的数据之前,进度对话框被关闭