• <small id='j8Vz7'></small><noframes id='j8Vz7'>

      <bdo id='j8Vz7'></bdo><ul id='j8Vz7'></ul>

      <i id='j8Vz7'><tr id='j8Vz7'><dt id='j8Vz7'><q id='j8Vz7'><span id='j8Vz7'><b id='j8Vz7'><form id='j8Vz7'><ins id='j8Vz7'></ins><ul id='j8Vz7'></ul><sub id='j8Vz7'></sub></form><legend id='j8Vz7'></legend><bdo id='j8Vz7'><pre id='j8Vz7'><center id='j8Vz7'></center></pre></bdo></b><th id='j8Vz7'></th></span></q></dt></tr></i><div id='j8Vz7'><tfoot id='j8Vz7'></tfoot><dl id='j8Vz7'><fieldset id='j8Vz7'></fieldset></dl></div>
    1. <tfoot id='j8Vz7'></tfoot>

        <legend id='j8Vz7'><style id='j8Vz7'><dir id='j8Vz7'><q id='j8Vz7'></q></dir></style></legend>
      1. 显示 SQL 结果时 nl2br() 不起作用

        时间:2023-10-16
      2. <tfoot id='QZctK'></tfoot>
      3. <legend id='QZctK'><style id='QZctK'><dir id='QZctK'><q id='QZctK'></q></dir></style></legend>
        <i id='QZctK'><tr id='QZctK'><dt id='QZctK'><q id='QZctK'><span id='QZctK'><b id='QZctK'><form id='QZctK'><ins id='QZctK'></ins><ul id='QZctK'></ul><sub id='QZctK'></sub></form><legend id='QZctK'></legend><bdo id='QZctK'><pre id='QZctK'><center id='QZctK'></center></pre></bdo></b><th id='QZctK'></th></span></q></dt></tr></i><div id='QZctK'><tfoot id='QZctK'></tfoot><dl id='QZctK'><fieldset id='QZctK'></fieldset></dl></div>

            <bdo id='QZctK'></bdo><ul id='QZctK'></ul>

              <small id='QZctK'></small><noframes id='QZctK'>

                  <tbody id='QZctK'></tbody>

                • 本文介绍了显示 SQL 结果时 nl2br() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的 Joomla 模块上,我们使用以下代码从数据库中获取喊声

                  On my Joomla module, we are using the following code to get shouts from the database

                  function getShouts($number, $timezone, $message) {
                      $shouts = array();
                      $db = JFactory::getDBO();
                      $query = $db->getQuery(true);
                      $query->select('*')
                      ->from('#__shoutbox')
                      ->order('id DESC');
                      $db->setQuery($query , 0 , $number);
                      $rows = $db->loadObjectList();
                      $i=0;
                      foreach ( $rows as $row ) {
                          $shouts[$i]->id = $row->id;
                          $shouts[$i]->name = $row->name;
                          $shouts[$i]->msg = $row->msg;
                          $i++;
                      }
                      return $shouts;
                  }
                  

                  和下面的代码显示在default.php

                  print stripslashes($shouts[$i]->msg);
                  

                  然而,当有人想要输入如下内容时,这会导致问题:

                  However this is causing problems when someone wants to input something like the following:

                  test line 1
                  test line 2
                  

                  如果他们换行,则帖子在提交后显示如下:

                  If they go onto a new line, the post displays like so after being submitted:

                  test line 1rntest line 2
                  

                  所以我做了一些研究并意识到我必须使用 nl2br() ,我做了如下所示:

                  So I did some research and realised I had to use nl2br() which I did as shown below:

                  print stripslashes(nl2br($shouts[$i]->msg));
                  

                  然而,它似乎并没有解决问题.我还尝试在 helper 中创建另一个函数以使用 preg_replace 替换它,但这也无济于事.

                  however, it didn't seem to resolve the issue. I also tried creating another function in the helper to replace it using preg_replace but this didn't help either.

                  谁能解释为什么在添加 nl2br() 后换行不起作用以及如何修复它?

                  Can anyone explain why line breaking isn't working after adding nl2br() and how to fix it?

                  推荐答案

                  试试这个:

                  print nl2br(stripcslashes($shouts[$i]->msg));
                  

                  注意 stripcslashes() 函数,而不是 stripslashes()

                  Pay attention to the stripcslashes() function, but not stripslashes()

                  或者只是:

                  print nl2br($shouts[$i]->msg);
                  

                  UPD: nl2br() 函数将 替换为
                  .问题是您的文本中没有 ,但有 n\n.我认为从 base 获取数据时没有必要使用 stripslashes() ,除非你在 base 中删除了数据.

                  UPD: nl2br() function replaces with <br />. The problem is that you don't have in your text, but have n or \n. I think there is no need to use stripslashes() when you get data from base, except the situation when you have ecranized data in your base.

                  这篇关于显示 SQL 结果时 nl2br() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存 下一篇:Joomla 包含数据库功能

                  相关文章

                • <small id='dYL63'></small><noframes id='dYL63'>

                • <i id='dYL63'><tr id='dYL63'><dt id='dYL63'><q id='dYL63'><span id='dYL63'><b id='dYL63'><form id='dYL63'><ins id='dYL63'></ins><ul id='dYL63'></ul><sub id='dYL63'></sub></form><legend id='dYL63'></legend><bdo id='dYL63'><pre id='dYL63'><center id='dYL63'></center></pre></bdo></b><th id='dYL63'></th></span></q></dt></tr></i><div id='dYL63'><tfoot id='dYL63'></tfoot><dl id='dYL63'><fieldset id='dYL63'></fieldset></dl></div>

                    <legend id='dYL63'><style id='dYL63'><dir id='dYL63'><q id='dYL63'></q></dir></style></legend>

                    <tfoot id='dYL63'></tfoot>
                        <bdo id='dYL63'></bdo><ul id='dYL63'></ul>