How to force PHP to read newlines and returns as <br>

耗尽温柔 提交于 2019-12-20 05:00:08

问题


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

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

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

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!

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?


回答1:


You can use

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

Example from Manual:

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

will output

Welcome<br>
This is my HTML document


来源:https://stackoverflow.com/questions/5107029/how-to-force-php-to-read-newlines-and-returns-as-br

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!