如何在打印时保留存储在数据库中的文本格式


How to retain formating of text as stored in db while printing

我正在使用php从数据库中获取结果。在数据库中,我有很多输入和选项卡的 c 代码,以便更好地理解。

 #include<stdio.h>
 main()
{
printf("Hello World");
}

但是问题出在输出中,当我打印它时,我在一行中得到输出。

 #include main() { printf("Hello World"); }

我怎样才能以存储在数据库中的正确格式生成输出。

您可以使用 html <pre> balise 来保留要显示的文本的格式。

当您回显打印数据时,请使用

nl2br();

然后像

echo nl2br($data_from_db);