无法获得与php中mysql数据库中存储的格式相同的格式

无法获得与php中mysql数据库中存储的格式相同的格式,php,html,mysql,line-breaks,nl2br,Php,Html,Mysql,Line Breaks,Nl2br,我在数据库中存储了一些数据,如下所示:- main() { int num; printf("please enter a number"); } 获取此字段后,我希望在使用nl2br()函数时使用相同的格式,但显示如下:- main() { int num; printf("please enter a number"); } i、 e不使用空格..请帮助我..谢谢HTML将跳过多个空格和新行。当你使用nl2br时,你

我在数据库中存储了一些数据,如下所示:-

  main()
      {
           int num;
           printf("please enter a number");
      }
获取此字段后,我希望在使用nl2br()函数时使用相同的格式,但显示如下:-

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

i、 e不使用空格..请帮助我..谢谢

HTML将跳过多个空格和新行。当你使用nl2br时,你可以简单地在一组
中输出整个内容。当在网页上打印多个空格字符时,只显示一个空格

$string='Some funky
formatting with spaces and
    some additional indenting...";

echo "<pre>".$string."</pre>";
要保留空白,您需要执行以下操作:

使用
标记(预格式化),该标记将使用单间距字体并保留所有空白


文本到处都是
这里,这里,还有一些
Some funky
formatting with spaces and
    some additional indenting...
echo nl2br(str_replace(" ", "&nbsp;", $content));
<pre>
text goes here and here 
         and here and here            Some out here
</pre>