954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Output MySQL text field formatted

Hi,

I have a text data type field in MySQL table that I need to read out to a page. When the value is entered into this text field the value will have returns as follows:

------------------
TEST TEST aaaaaaaa

asdasdasdfas

3rd lineasadas
----------------
When I read this value out and display in php page in the browser, the returns are not there and I get it all in one line:
-----------------------
TEST TEST aaaaaaaaasdasdasdfas3rd lineasadas
-------------------

What can I do to have he returns show up?

Thanks,
Juls

Juls
Newbie Poster
3 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

In the webpage you can use str_replace:

$text = $row['text'];
$text = str_replace("\n", "
", $text);
echo $text;

To prnt in one line, ignore the str_replace part.

zippee
Posting Whiz in Training
294 posts since Jan 2005
Reputation Points: 10
Solved Threads: 7
 

Sir,

I am new to MySql.

I am facing Installation Problem.

Kindly do the Needful.

Ashwin Perti

ashwinperti
Newbie Poster
22 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

Juls - PHP has a built in function to convert line feeds to
elements. It is nl2br, and it's use is:
[PHP]echo( nl2br("this is a line\nthis is another line") )
/** prints as
this is a line

this is another line
*/[/PHP]

ashwinperti - suggest you start your own thread rather than trying to hijack others. You'll get a better response if you describe what your problem is and what your operating environment is.

Lafinboy
Junior Poster
172 posts since Jul 2004
Reputation Points: 16
Solved Threads: 7
 

nl2br is the function which assist you to change enter as jump line.

Hope it helps

In the webpage you can use str_replace:

$text = $row['text']; $text = str_replace("\n", "
", $text); echo $text;

To prnt in one line, ignore the str_replace part.

Mckcvision
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

nl2br is the function to replace enter with

Mckcvision
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You