php - 没有获得与 php 中 mysql 数据库中存储的格式相同的格式

标签 php html mysql line-breaks nl2br

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

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

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

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

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

最佳答案

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...

关于php - 没有获得与 php 中 mysql 数据库中存储的格式相同的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18914345/

相关文章:

javascript - execCommand ('copy' ) 在 Ajax/XHR 回调中不起作用?

html - 覆盖 Bootstrap 默认字体(最佳实践)

php - 从数据库填充的下拉列表不使用 PHP 记录选定的选项

mysql - 如何编写分析关键字使用频率的 SQL 语句?

php - 插入和更新 MySQL 表

php - 我怎样才能 "unset"一个已经声明的类

html - CSS多图像定位和样式

mysql - Node.js MySQL 批量插入操作失败

php - 在 PHP 中使用 '@' 是开箱即用的选项吗?

php - 获取字段和组连接的计数