如何强制PHP读取换行符并以< br>返回 [英] How to force PHP to read newlines and returns as <br>

查看:209
本文介绍了如何强制PHP读取换行符并以< br>返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,标题有点过头了.但是情况是什么.

The title is a little off im sorry. however what the scenario IS.

我正在从MySQL数据库中读取字段格式为"mediumtext".

I'm reading from a MySQL Database the field format is "mediumtext".

目前,它知道何时按回车键会返回一个新行.不涉及html.

At current it knows when there is a new line from hitting enter/return. there is no html involved.

但是,当我将其从数据库中拉到页面上时,没有格式.但是,如果您查看html的代码,它会用新行漂亮地格式化!

however when i pull this from the database onto my page, there is no formatting. however if you look at the html the code it beautifuly formatted with new lines!

我已经为一些简单的BBCode提供了查找/替换功能设置,因此也许可以使用它.

ive already got a find/replace function setup for some simple BBCode so might be able to use this.

有人对我如何使用查找/替换来查找换行符"有想法吗?或者如果您理解我的话,如何简单地强制新行?

so does anybody have ideas on how I can either use my find/replace to find "new lines?" or how to simply force the new lines some how, if you understand me?

推荐答案

您可以使用

  • nl2br — Inserts HTML line breaks before all newlines in a string

手册中的示例:

echo nl2br("Welcome\r\nThis is my HTML document", false);

将输出

Welcome<br>
This is my HTML document

这篇关于如何强制PHP读取换行符并以&lt; br&gt;返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆