PHP MYSQL使用新行获取TEXT [英] PHP MYSQL fetching a TEXT with new lines

查看:59
本文介绍了PHP MYSQL使用新行获取TEXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php

//after connecting etc..
        $username = $_SESSION['username'];
        $string = "SELECT msg FROM $table WHERE username='$username'";
    $result = mysql_fetch_array(mysql_query($string)) or die(mysql_error());
    echo $result[msg];
?>

数据库就是这样.

I wanted to install the database base.
I wanted to install the database server.
I wanted to install the Ubuntu.

当我检索它们时,它们显示为.

when i retrieve them they appear as..

I wanted to install the database base.I wanted to install the database server.I wanted to install the Ubuntu.

它是一个TEXT字段.是否有办法使它们以新行显示?完全一样吗?

Its a TEXT field.. is there a way to make them appear with the new lines? exactly the same?

非常感谢!

推荐答案

使用此:

echo nl2br($result[msg]);

只要浏览器不将\r\n视为真正的换行符-您需要使用将它们转换"为<br> nl2br()

As long as browsers doesn't treat \r\n as real new-lines - you need to "convert" them to <br>'s with nl2br()

这篇关于PHP MYSQL使用新行获取TEXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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