问题
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