【问题标题】:Not getting same format as stored in mysql database in php没有得到与存储在 php 中的 mysql 数据库中相同的格式
【发布时间】:2013-09-25 16:46:07
【问题描述】:

我在数据库中存储了一些数据:-

  main()
      {
           int num;
           printf("please enter a number");
      }

获取此字段后,我在使用 nl2br() 函数时想要相同的格式,但它显示如下:-

main()
{
int num;
printf("please enter a number");
}

即不占用空间..请帮助我..谢谢

【问题讨论】:

    标签: php html mysql line-breaks nl2br


    【解决方案1】:

    HTML 将跳过多个空格和换行符。虽然您可以使用 nl2br,但您可以简单地在一组 <pre> 中输出整个内容,然后使用 ` 标签将其完全显示在您的数据库中。

    一个例子是这样做:

    $string='Some funky
    formatting with spaces and
        some additional indenting...";
    
    echo "<pre>".$string."</pre>";
    

    输出将是:

    Some funky
    formatting with spaces and
        some additional indenting...
    

    【讨论】:

      【解决方案2】:

      在网页上打印多个空格字符时,仅显示一个空格。

      要保留空白,您需要执行以下操作:

      echo nl2br(str_replace(" ", "&nbsp;", $content));
      

      【讨论】:

        【解决方案3】:

        使用&lt;pre&gt; 标签(预先格式化),它将使用单行距字体并保留所有空白

        <pre>
        text goes here and here 
                 and here and here            Some out here
        </pre>
        

        【讨论】:

          猜你喜欢
          • 2019-10-02
          • 2015-05-26
          • 1970-01-01
          • 2010-12-19
          • 1970-01-01
          • 2012-02-11
          • 2022-01-12
          • 2010-10-17
          • 2021-04-19
          相关资源
          最近更新 更多