回显字符串并不总是显示单个引号

时间:2021-04-05 20:44:21

标签: php html mysql

我有一个网站 (link),其中用户故事显示在取自 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);

0 个答案:

没有答案
相关问题