• 之外的数据上的Nl2br标签
  • 发布于 2024-11-19 05:57:28 字数 1285 浏览 6 评论 0原文

    我希望能够从 mysql 获取 html 格式的数据,并将新行转换为

    标签。

    我已经能够通过 CSS 中的 white-space: pre-wrap 有效地做到这一点,除了 IE7 及以下版本。

    我的问题是,如果我在浏览器为 <=IE7 的情况下在数据上放置条件 nl2br() ,那么它会在

  • 标记上创建换行符,该标记已经有换行符,在子弹之间创造额外的空间。
  • 有更好的方法吗?

    我的测试页面是:

    http://logblog.net84.net/

    我的代码是(此时在时间):

    ...
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Untitled Document</title>
            </head>
            <style>
            p { white-space:pre-wrap;white-space:-moz-pre-wrap;word-wrap:break-word }
            </style>
            <body>
            <?php 
    ...
            $conn = mysql_connect($host, $user, $pw) or die('Error connecting to mysql');
            mysql_select_db($db);
            mysql_set_charset('utf8', $conn);
            $result = mysql_query("SELECT * FROM wp_posts WHERE post_status='publish' AND post_type='post'");
    
            while($row = mysql_fetch_array($result))
              {
              echo '<h2>'.$row['post_title'].'</h2>'; 
              echo '<p>'.$row['post_content'].'</p>';
              }
        ...
    

    I would like to be able to get html-formatted data from mysql, and turn the new lines into <br> or <p> tags.

    I have been able to do this effectively with white-space: pre-wrap in the CSS, except for with IE7 and under.

    My issue is that if I put a conditional nl2br() on the data if the browser is <=IE7, then it would create line breaks on the <li> tags, which already have line breaks, creating extra space between the bullets.

    Is there a better way to do this?

    My test page is:

    http://logblog.net84.net/

    And my code is (at this point in time):

    ...
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Untitled Document</title>
            </head>
            <style>
            p { white-space:pre-wrap;white-space:-moz-pre-wrap;word-wrap:break-word }
            </style>
            <body>
            <?php 
    ...
            $conn = mysql_connect($host, $user, $pw) or die('Error connecting to mysql');
            mysql_select_db($db);
            mysql_set_charset('utf8', $conn);
            $result = mysql_query("SELECT * FROM wp_posts WHERE post_status='publish' AND post_type='post'");
    
            while($row = mysql_fetch_array($result))
              {
              echo '<h2>'.$row['post_title'].'</h2>'; 
              echo '<p>'.$row['post_content'].'</p>';
              }
        ...
    

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    骑趴 2024-11-26 05:57:28

    您是否想绕过 WordPress 的自动段落替换?如果是这样,有一个内置函数适合您 - http://codex.wordpress.org/Function_Reference/ wpaautop

    如果不是这个,那么你能更具体一点吗 - 看起来你的测试页面链接没有出现在帖子上?

    Are you trying to get around WordPress's automatic Paragraph replacement? If so there is a built-in a function for you - http://codex.wordpress.org/Function_Reference/wpautop

    If not this then can you be a little more specific - it looks like your test page link did not come through on the post?

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文